Skip to main content

Module: utils

Functions

assertUnreachable

assertUnreachable(variable, message?): never

Parameters

NameType
variablenever
message?string

Returns

never

Defined in

packages/webapp-libs/webapp-core/src/utils/assertUnreachable.tsx:1


camelCaseKeys

camelCaseKeys(object): Record<string, any>

Translate all top-level keys of the given object to camelCase.

Parameters

NameType
objectRecord<string, any>

Returns

Record<string, any>

Defined in

packages/webapp-libs/webapp-core/src/utils/object.ts:6


getLocalePath

getLocalePath(p): string

Parameters

NameType
pstring

Returns

string

Defined in

packages/webapp-libs/webapp-core/src/utils/path.ts:3


nestedPath

nestedPath<T>(root, nestedRoutes): { index: string } & T & { getLocalePath: (route: keyof T) => string ; getRelativeUrl: (route: keyof T) => T[keyof T] }

Helper function to define typed nested route config

Type parameters

NameType
Textends object

Parameters

NameType
rootstring
nestedRoutesT

Returns

{ index: string } & T & { getLocalePath: (route: keyof T) => string ; getRelativeUrl: (route: keyof T) => T[keyof T] }

Example

In route config

import { nestedPath } from '@shipfast/webapp-core/utils';

export const RoutesConfig = {
example: nestedPath('example', {
list: '',
details: ':id',
edit: ':id/edit',
add: 'add',
}),
};

Example

When defining a route component

import { Route } from 'react-router-dom';

<Route path={RoutesConfig.example.edit} element={<CrudDemoItemEdit />} />

Example

When creating a link

import { useGenerateLocalePath } from '@shipfast/webapp-core/hooks';
import { Link } from 'react-router-dom';

const Example = () => {
const generateLocalePath = useGenerateLocalePath();

return (
<Link to={generateLocalePath(RoutesConfig.example.edit, { id: 'item-id' })}>
Press me
</Link>
)
}

Defined in

packages/webapp-libs/webapp-core/src/utils/path.ts:63