本文整理汇总了TypeScript中ramda.mapObjIndexed函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mapObjIndexed函数的具体用法?TypeScript mapObjIndexed怎么用?TypeScript mapObjIndexed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mapObjIndexed函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
export const clean = (obj) => {
const nilEmpty: any = R.mapObjIndexed((x , key) => (R.isEmpty(x)) ? undefined : x);
const nilComputed: any = R.mapObjIndexed((x , key) => (key.indexOf('$') >= 0) ? undefined : x);
const trimProps = R.map((n: any) => R.is(String, n) ? R.trim(n) : n);
const cleanNil = R.reject(R.isNil);
return R.pipe(nilEmpty, nilComputed, trimProps, cleanNil)(obj);
}
示例2: mapObjIndexed
export function method<
ClientsT extends IOClients = IOClients,
StateT = void,
CustomT = void
>(options: MethodOptions<ClientsT, StateT, CustomT>) {
const handlers = mapObjIndexed(
handler => compose(Array.isArray(handler) ? handler : [handler]),
options as Record<
string,
| RouteHandler<ClientsT, StateT, CustomT>
| Array<RouteHandler<ClientsT, StateT, CustomT>>
>
)
return async (
ctx: ServiceContext<ClientsT, StateT, CustomT>,
next: () => Promise<any>
) => {
const verb = ctx.method.toUpperCase()
const handler = handlers[verb] || handlers.DEFAULT
if (handler) {
await handler(ctx)
}
await next()
}
}
示例3: countPerOrigin
function countPerOrigin (obj: { [key: string]: any[] }) {
try {
return mapObjIndexed(val => val.length, obj)
} catch (_) {
return {}
}
}
示例4: wrapForeignOpt
export const associationDecorator = ({ modelName, fields }: { modelName: string; fields }) => {
const TAG = '[associationDecorator]';
logger.log(TAG, { fields });
// prettier-ignore
const associationFields = R.filter(R.compose(R.not, R.isNil, R.prop('associations')))(fields);
logger.log(TAG, { associationFields }, R.not(R.isEmpty(associationFields)));
if (R.not(R.isEmpty(associationFields))) {
const wrapForeignOpt = R.map(opt => ({
...opt,
association: AppContext.adapters.models.getAssociationConfigs(opt.modelName),
}));
const withAssociations = R.mapObjIndexed(field => ({
...field,
foreignOpts: wrapForeignOpt(field.foreignOpts),
}))(associationFields);
logger.debug(TAG, { withAssociations, wrapForeignOpt });
const wrappedFields = R.mergeDeepRight(fields, withAssociations);
logger.debug(TAG, { wrappedFields });
return { modelName, fields: wrappedFields };
}
return { modelName, fields };
};
示例5: overrideConfigKeyFromEnv
private overrideConfigKeyFromEnv() {
this.configMap = R.mapObjIndexed((value: string, key: string, config: any) => {
if (process.env[key]) {
config[key] = process.env[key];
}
return config[key];
}, this.configMap);
}
示例6: toArray
/**
* Convert a object to array
* @param obj The object to be converted to array
*/
static toArray(obj) {
let array = [];
if (obj) {
const toArray = R.mapObjIndexed((val, key) => array.push({ $key: key, value: val }));
const loadArray = toArray(obj)
}
return array;
}
示例7: MockAssetResolver
const runTests = <S, F>(
assert: (
fixture: ExerciseFixture<S, F>,
/* tslint:disable-next-line:no-any */
exercise: AbstractExercise<any, S, F>
) => void
) => {
const resolver = new MockAssetResolver();
const factory = new EntityFactory(resolver);
const cases = values(
mapObjIndexed(
(
E: {
fixtures: Array<ExerciseFixture<S, F>>;
/* tslint:disable-next-line:no-any */
new (p: any): AbstractExercise<any, S, F>;
},
type
) => () => {
forEach(fixture => {
try {
const exercise = factory.createExercise(
type as ExerciseTypes,
fixture.props
);
// Catch test failures so that we can pass a custom message
assert(fixture, exercise);
} catch (e) {
throw new Error(`${type} âş ${fixture.name}:\n${e.message}`);
}
}, E.fixtures);
},
Exercises
)
);
// Execute the test runners
forEach(runTestCases => runTestCases(), cases);
// Check that each test case was run
const numberOfAssertions = sum(
values(
map<
{ [type: string]: { fixtures: Array<ExerciseFixture<S, F>> } },
{ [type: string]: number }
>(
(E: { fixtures: Array<ExerciseFixture<S, F>> }) => E.fixtures.length,
Exercises
)
)
);
expect.assertions(numberOfAssertions);
};
示例8: curryN
let transformReq = curryN(2, (req: Request, multipart: boolean) => ifElse(
() => multipart,
pipe<any, any, any, any>(
mapObjIndexed((v: any, k: string) => v
? req[propOr(false, 'path', v) ? 'attach' : 'field'](k, v)
: req),
values,
last
),
req.send.bind(req)
))
示例9: clean
/**
* Return a clean part of the model for updating to database
*/
static clean(model) {
const removeComputedProps = R.pipe(
R.mapObjIndexed((x , key) => {
if (key.indexOf('$') >= 0) { return undefined }
return x;
}),
R.reject(R.isNil)
);
const trimValues = R.map(n => { return R.is(String, n) ? R.trim(n) : n });
const removeNullFields = R.reject(R.isNil)
return R.pipe(removeComputedProps, trimValues, removeNullFields)(model);
}
示例10: mapObjIndexed
], (active, byName) => {
// TODO We might want to use the selected preset values (pass from host frame or content canvas) instead of individual dimension values
if (active !== null) {
return mapObjIndexed((dimensionValues, name) => {
const dimensionConfiguration = byName[name];
const presets = dimensionConfiguration.presets;
const activePreset = Object.keys(presets).find(dimensionName => presets[dimensionName].values === dimensionValues);
const presetName = activePreset || dimensionConfiguration.defaultPreset;
const finalActivePreset = presets[presetName];
return Object.assign({}, finalActivePreset, {name: presetName});
}, active);
}
return {};
});
示例11: telegramDriver
function telegramDriver (sourceRequest: Observable<Observable<DriverSink>>, runSA: StreamAdapter): DriverExecution {
let adapt = adapter(runSA)
let request = sourceRequest.map(x => convertStream(x, runSA, RxAdapter))
if (isWebhookResponse(request, options)) {
handleWebhook(token, request, proxyWebHook)
}
let responses = handleRequest(token, request as Observable<Observable<TcombRequest>>).share()
responses.subscribeOnError((err: any) => console.error('request error: ', err))
return Object.assign(
{
token,
dispose: () => disposable.dispose()
},
mapObjIndexed(adapt, {
events: makeEventsSelector(sources),
updates,
responses
})) as DriverExecution
}