lodash-es#mapValues TypeScript Examples
The following examples show how to use
lodash-es#mapValues.
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: IconGallery.tsx From UUI with MIT License | 6 votes |
export function IconGallery<
N extends string,
P extends {
[key in N]: Partial<Pick<IconProps, 'mode'>> & Pick<IconProps, 'source'>
},
M extends IconProps['mode'] | undefined,
O extends IconGalleryOptions<M>,
V extends {
[key in keyof P]: LoadedIconByMode<P[key]['mode']> extends undefined
? (O extends undefined
? never
: (LoadedIconByMode<O['mode']> extends undefined ? never : LoadedIconByMode<O['mode']>)
)
: LoadedIconByMode<P[key]['mode']>
}
>(initials: P, options?: O): V {
return mapValues(initials, (value) => {
const MemoIcon = React.memo((props: IconProps) => {
return <Icon {...options} {...value} {...props}></Icon>
}, isEqual);
(MemoIcon.type as React.SFC).displayName = `<UUI> IconGallery WrappedIcon`;
return MemoIcon;
}) as any
}
Example #2
Source File: UUIComponent.tsx From UUI with MIT License | 6 votes |
function compileNodes(options: any): any {
return mapValues(options.nodes, (nodeElement, nodeName) => {
if (isString(nodeElement)) {
return IntrinsicNode(nodeElement as any, nodeName, options)
} else {
return ComponentNode(nodeElement as any, nodeName, options)
}
})
}
Example #3
Source File: old-proof-adapter.ts From capture-lite with GNU General Public License v3.0 | 6 votes |
export function getTruth(
sortedProofInformation: SortedProofInformation
): Truth {
const groupedByProvider = groupObjectsBy(
sortedProofInformation.information.map(info => ({
provider: info.provider,
name: replaceOldDefaultInformationNameWithDefaultFactId(info.name),
value: info.value,
})),
'provider'
);
const groupedByProviderAndName = mapValues(groupedByProvider, v =>
groupObjectsBy(v, 'name')
);
const providers = mapValues(groupedByProviderAndName, value =>
mapValues(value, arr => toNumberOrBoolean(arr[0].value))
);
return { timestamp: sortedProofInformation.proof.timestamp, providers };
}
Example #4
Source File: old-proof-adapter.ts From capture-lite with GNU General Public License v3.0 | 6 votes |
/**
* Group by the key. The returned collection does not have the original key property.
*/
function groupObjectsBy<T extends Record<string, any>>(
objects: T[],
key: string
) {
return mapValues(groupBy(objects, key), values =>
values.map(v => {
delete v[key];
return v;
})
);
}
Example #5
Source File: old-proof-adapter.ts From capture-lite with GNU General Public License v3.0 | 5 votes |
export function getSignatures(oldSignatures: OldSignature[]): Signatures {
return mapValues(groupObjectsBy(oldSignatures, 'provider'), values => ({
signature: values[0].signature,
publicKey: values[0].publicKey,
}));
}
Example #6
Source File: onInitialize.ts From github-deploy-center with MIT License | 4 votes |
onInitializeOvermind = ({
state,
effects: { storage },
reaction,
}: Context) => {
function sync<T>(
getState: (state: AppState) => T,
onValueLoaded: (value: T) => void,
options: { nested: boolean },
onValueChanged: (value: T) => void = noop
) {
const key = getState.toString().replace(/^.*?\./, 'gdc.')
reaction(
getState,
(data) => {
onValueChanged(data)
storage.save(key, data)
},
{
nested: options.nested,
}
)
const value = storage.load(key)
if (value) {
onValueLoaded(value)
}
}
sync(
(state) => state.token,
(token) => {
state.token = token || ''
},
{ nested: false },
(token) => {
graphQLApi.setToken(token)
restApi.setToken(token)
}
)
sync(
(state) => state.applicationsById,
(data) => {
state.applicationsById = pipe(
ApplicationsByIdCodec.decode(data),
getOrElse((e) => {
console.error(e)
return {}
})
)
},
{ nested: true }
)
sync(
(state) => state.selectedApplicationId,
(id) => (state.selectedApplicationId = id),
{ nested: false }
)
sync(
(state) => state.appSettings,
(data) => {
state.appSettings = pipe(
AppSettingsCodec.decode(data),
getOrElse((e) => {
console.error(e)
return defaultAppSettings
})
)
},
{ nested: true }
)
sync(
(state) => state.pendingDeployments,
(data) => {
state.pendingDeployments = pipe(
PendingDeploymentsCodec.decode(data),
getOrElse((e) => {
console.error(e)
return {} as Record<string, string>
}),
(data) => mapValues(data, (date) => dayjs(date))
)
},
{ nested: true }
)
}
Example #7
Source File: code-generator.ts From openapi-generator-typescript with MIT License | 4 votes |
generatePathsDefinition = (
pathsObject: PathsObject,
operations?: ReadonlyArray<string>
) =>
pathsObjectEntries(pathsObject, operations)
.map(x => {
const { method, path: url, operationObject, operationIdIdentifier } = x;
// TODO: 忽略了所有的 ReferenceObject
const parameters = (operationObject.parameters ?? []).filter(
isNotReferenceObject
);
const pathParameters = parameters.filter(x => x.in === 'path');
const queryParameters = parameters.filter(x => x.in === 'query');
const cookieParameters = parameters.filter(x => x.in === 'cookie');
const headerParameters = parameters.filter(x => x.in === 'header');
const parsedUrl = parseUrlTemplate(url);
const conflictParameters = difference(
parameters,
pathParameters
).filter(x => parsedUrl.pathParams.includes(x.name));
if (conflictParameters.length > 0) {
console.warn(
`operation ${operationObject.operationId} has conflictParameters, url: ${url}, conflictParameters:`,
conflictParameters
);
}
const freePathVariables = difference(
parsedUrl.pathParams,
pathParameters.map(x => x.name)
);
if (freePathVariables.length > 0) {
console.warn(
`operation ${operationObject.operationId} has freePathVariables, url: ${url}, freePathVariables:`,
freePathVariables
);
}
const interfacePathParameter =
pathParameters.length === 0 && parsedUrl.pathParams.length === 0
? ''
: `export interface PathParameter {
${
pathParameters.length === 0
? ''
: getObjectBody({
type: 'object',
required: pathParameters.filter(x => x.required).map(x => x.name),
properties: fromEntries([
...pathParameters.map(x => [x.name, { ...x.schema! }] as const),
]),
}) + '\n'
}${formatEntries(
freePathVariables.map(key => ({
key,
value: 'string | number, // FIXME: free variable here',
modifiers: ['readonly'],
})),
{
endSeparator: '',
}
)}
}
`;
const formatContent = (
interfaceName: string,
parameterObjectList: ReadonlyArray<ParameterObject>
) =>
parameterObjectList.length === 0
? ''
: `export interface ${interfaceName} ${getObject({
type: 'object',
required: parameterObjectList
.filter(x => x.required)
.map(x => x.name),
properties: fromEntries([
...parameterObjectList.map(x => [x.name, x.schema!] as const),
]),
})}`;
const responsesEntries = Object.entries(operationObject.responses).map(
([statusCode, object]) =>
({
statusCode,
responseObject: object as ResponseObject, // FIXME: 这里没有考虑 referenceObject 的情况
} as const)
);
const responseInterfaceBody = getObject({
type: 'object',
required: responsesEntries.map(({ statusCode }) => statusCode),
properties: fromEntries(
responsesEntries.map(
({
responseObject: { content },
statusCode,
}): readonly [string, SchemaObject] =>
content === undefined
? [
statusCode,
{
type: 'object',
},
]
: [
statusCode,
{
type: 'object',
required: Object.keys(content),
properties: mapValues(content, ({ schema }) => schema!),
},
]
)
),
});
const getUrlFunction =
parsedUrl.pathParams.length > 0
? `({ ${parsedUrl.pathParams.join(', ')} }: PathParameter) => \`${
parsedUrl.urlJsTemplate
}\``
: `({} : {}) => '${parsedUrl.urlJsTemplate}'`;
const interfaceQueryParameter = formatContent(
'QueryParameter',
queryParameters
);
const interfaceHeaderParameter = formatContent(
'HeaderParameter',
headerParameters
);
const interfaceCookieParameter = formatContent(
'CookieParameter',
cookieParameters
);
const interfaceAllParameters =
interfacePathParameter +
interfaceQueryParameter +
interfaceHeaderParameter +
interfaceCookieParameter;
const requestBody = (operationObject.requestBody as RequestBodyObject)
?.content
? (operationObject.requestBody as RequestBodyObject)
: undefined;
const requestBodyContent = requestBody?.content ?? {};
const requestBodyInterfaceBody = getObject({
type: 'object',
required: Object.keys(requestBodyContent),
properties: mapValues(requestBodyContent, ({ schema }) => schema!),
});
const content = `
export const method = '${method}';
export const url = '${url}';
export const getUrl = ${getUrlFunction};
export const parameterNames = ${JSON.stringify({
path: pathParameters.map(x => x.name),
query: queryParameters.map(x => x.name),
header: headerParameters.map(x => x.name),
cookie: cookieParameters.map(x => x.name),
})} as const
${interfaceAllParameters}
export type Parameter = ${
interfaceAllParameters === ''
? '{}'
: '' +
([
['PathParameter', interfacePathParameter],
['QueryParameter', interfaceQueryParameter],
['HeaderParameter', interfaceHeaderParameter],
['CookieParameter', interfaceCookieParameter],
] as const)
.filter(x => x[1] !== '')
.map(x => x[0])
.join(' & ')
};${
conflictParameters.length === 0 ? '' : ' // FIXME: Conflict Parameters'
}
export interface Response ${responseInterfaceBody}
export const requestBody = ${
JSON.stringify(requestBody) +
(requestBody === undefined ? '' : ' as const')
};
export interface RequestBody ${requestBodyInterfaceBody}
`;
return `
${getOperationObjectJSDoc(x)}
export namespace ${operationIdIdentifier} {
${addIndentLevel(content)}
}`;
})
.join('')