querystring#parse TypeScript Examples

The following examples show how to use querystring#parse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: login.view.tsx    From malagu with MIT License 6 votes vote down vote up
export function Login() {
    const location = useLocation();
    const size = useContext(ResponsiveContext);
    const intl = useIntl();
    const targetUrlParameter = ConfigUtil.get<string>('malagu.security.targetUrlParameter');
    const registrations = ConfigUtil.get<{[key: string]: { icon?: string, clientName: string } }>('malagu.oauth2.client.registrations');
    const redirect = parse(location.search && location.search.substring(1))[targetUrlParameter];
    const queryStr = redirect ? `?${stringify({ [targetUrlParameter]: redirect})}` : '';
    return (
    <StyledWraper style={size === 'small' ? { top: 0, bottom: 0, right: 0, left: 0 } : undefined }>
        <StyledContainer size={size}>
            <Box direction="column" pad="large" align="center" background="brand" round={ size === 'small' ? undefined : { corner: 'top', size: '4px' } }>
                <Button plain
                    href={ConfigUtil.get('accounts.home.url')}
                    icon={<Icon size="large" color="white" icon={ConfigUtil.get('accounts.logo.icon')}></Icon>}>
                </Button>
                <Heading level="4" color="white">{intl.formatMessage({ id: 'accounts.logo.label' })}</Heading>
            </Box>
            <Box direction="column" align="center" animation="slideDown">
                <Heading level="6">{intl.formatMessage({ id: 'accounts.quick.login.label' })}</Heading>
                <Nav>
                    {
                        Object.keys(registrations).map(id => (
                            <Button
                                hoverIndicator
                                icon={<Icon icon={registrations[id].icon || registrations[id].clientName} size="large"></Icon>}
                                href={`/oauth2/authorization/${id}${queryStr}`}>
                            </Button>
                        ))
                    }
                </Nav>
            </Box>
            <Box direction="column" fill="horizontal" style={ { position: 'absolute', bottom: 0 } } align="center">
                <LocaleMenu size="small" fontSize="12px"/>
            </Box>
        </StyledContainer>
    </StyledWraper>);

}
Example #2
Source File: index.ts    From uni-cloud-router with Apache License 2.0 6 votes vote down vote up
function extend(ctx: Context, isHttpRequest: boolean) {
  if (isHttpRequest) {
    const { headers, httpMethod, body, queryStringParameters } = ctx.event
    initContextType(headers)
    ctx.query = queryStringParameters
    if (httpMethod === 'GET') {
      ctx.data = ctx.query
    } else {
      ctx.data = Object.create(null)
      if (body) {
        const contentType = headers[CONTENT_TYPE]
        if (isJsonType(contentType)) {
          try {
            ctx.data = JSON.parse(body)
          } catch (e) {}
        } else if (isFormType(contentType)) {
          ctx.data = parse(body)
        }
      }
    }
  }
  ctx.set = function set(field: Data | string, val?: string | string[]) {
    if (arguments.length === 2) {
      if (Array.isArray(val)) {
        val = val.map((v) => (typeof v === 'string' ? v : String(v)))
      } else if (typeof val !== 'string') {
        val = String(val)
      }
      ctx.headers[field as string] = val as string
    } else if (isObject(field)) {
      for (const key in field) {
        ctx.set(key, field[key])
      }
    }
  }
}
Example #3
Source File: utils.ts    From ant-design-pro-V4 with MIT License 6 votes vote down vote up
getPageQuery = () => parse(window.location.href.split('?')[1])
Example #4
Source File: utils.ts    From jetlinks-ui-antd with MIT License 6 votes vote down vote up
getPageQuery = () => parse(window.location.href.split('?')[1])
Example #5
Source File: utils.ts    From ui-visualization with MIT License 6 votes vote down vote up
getPageQuery = () => parse(window.location.href.split('?')[1])
Example #6
Source File: utils.ts    From dashboard with Apache License 2.0 6 votes vote down vote up
getPageQuery = () => parse(window.location.href.split('?')[1])
Example #7
Source File: utils.ts    From sidebar with Apache License 2.0 6 votes vote down vote up
getPageQuery = () => parse(window.location.href.split('?')[1])
Example #8
Source File: HandlerService.ts    From joplin-utils with MIT License 6 votes vote down vote up
async uriHandler(uri: Uri) {
    console.log('uriHandler: ', uri)
    const id = parse(uri.query).id as string
    switch (uri.path) {
      case '/open':
        await this.openNote(id)
        break
      case '/resource':
        await this.openResource(id)
        break
      default:
        vscode.window.showErrorMessage(i18n.t('Unprocessable link'))
    }
  }
Example #9
Source File: address.ts    From Account-Manager with MIT License 6 votes vote down vote up
parseQueryParams = (url: string): ParsedUrlQuery => {
  const questionMarkIndex = url.indexOf('?');
  if (questionMarkIndex === -1) return {};

  const parsedQueryParamObject = parse(url.slice(questionMarkIndex + 1));

  return Object.entries(parsedQueryParamObject).reduce((acc, [queryParam, value]) => {
    if (!value) return acc;

    if (Array.isArray(value))
      return {
        ...acc,
        [queryParam]: value.join(','),
      };

    return {
      ...acc,
      [queryParam]: value,
    };
  }, {});
}
Example #10
Source File: Post.spec.tsx    From space-traveling with MIT License 4 votes vote down vote up
describe('Post', () => {
  beforeAll(() => {
    mockedUseRouter.mockReturnValue({
      isFallback: false,
    });

    mockedPrismic.mockReturnValue({
      getByUID: () => {
        return Promise.resolve(mockedGetByUIDReturn);
      },
      query: () => {
        return Promise.resolve(mockedQueryReturn);
      },
    });
  });

  it('should be able to return prismic posts documents paths using getStaticPaths', async () => {
    const getStaticPathsReturn = [
      {
        params: {
          slug: 'como-utilizar-hooks',
        },
      },
      {
        params: {
          slug: 'criando-um-app-cra-do-zero',
        },
      },
    ];

    const getStaticPathsContext: GetStaticPathsContext = {};

    const response = (await getStaticPaths(
      getStaticPathsContext
    )) as GetStaticPathsResult;

    expect(response.paths).toEqual(getStaticPathsReturn);
  });

  it('should be able to return prismic post document using getStaticProps', async () => {
    const routeParam = parse('como-utilizar-hooks');

    const postReturn = mockedGetByUIDReturn;
    const getStaticPropsContext: GetStaticPropsContext<ParsedUrlQuery> = {
      params: routeParam,
    };

    const response = (await getStaticProps(
      getStaticPropsContext
    )) as GetStaticPropsResult;

    expect(response.props.post).toEqual(postReturn);
  });

  it('should be able to render post document info', () => {
    const postProps = mockedGetByUIDReturn;

    render(<Post post={postProps} />);

    screen.getByText('Como utilizar Hooks');
    screen.getByText('25 mar 2021');
    screen.getByText('Joseph Oliveira');
    screen.getByText('4 min');

    screen.getByText('Proin et varius');
    screen.getByText(/Nullam dolor sapien/);
    screen.getByText('Cras laoreet mi');
    screen.getByText(/Ut varius quis velit sed cursus/);
  });

  it('should be able to render loading message if fallback', () => {
    mockedUseRouter.mockReturnValueOnce({
      isFallback: true,
    });

    const postProps = mockedGetByUIDReturn;

    render(<Post post={postProps} />);

    screen.getByText('Carregando...');
  });

  it('should be able to render Header component', () => {
    const postProps = mockedGetByUIDReturn;

    render(<Post post={postProps} />);

    screen.getByAltText('logo');
  });
});