本文整理汇总了TypeScript中lodash.castArray函数的典型用法代码示例。如果您正苦于以下问题:TypeScript castArray函数的具体用法?TypeScript castArray怎么用?TypeScript castArray使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了castArray函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
return async (store: Store<State>) => {
const water: Partial<State> = {};
for (const paths of Object.values(saveOn)) {
for (const path of castArray(paths)) {
const storedValue = storage.getItem(prefixKey(path));
if (storedValue) {
const parsedValue = JSON.parse(storedValue);
set(water, path, parsedValue);
}
}
}
store.replaceState(merge({}, store.state, water));
if (onLoad) await onLoad(store);
store.subscribe(({ type }, state) => {
if (hasOwn(saveOn, type)) {
const paths = castArray(saveOn[type]);
for (const [path, value] of zip(paths, at(state, paths))) {
if (path === undefined) continue;
const stringifiedValue = JSON.stringify(value);
try {
storage.setItem(prefixKey(path), stringifiedValue);
} catch {
// this can sometimes throw based on the spec
}
}
}
});
};
示例2: castArray
export const effectiveness = (
attackingType: OneOrMany<Type>,
defendingType: OneOrMany<Type>,
options: TypeEffectivenessOptions = { gen: maxGen }
): [number, number] => {
const attackingTypes = castArray(attackingType);
let defendingTypes = castArray(defendingType);
if (options.grounded) {
defendingTypes = defendingTypes.filter(type => type !== Type.FLYING);
}
if (
options.immunity !== undefined &&
attackingTypes.includes(options.immunity) &&
!(options.grounded && options.immunity === Type.GROUND)
) {
return [0, 1];
}
let effectiveness = 1;
for (const dType of defendingTypes) {
if (options.freezeDry && dType === Type.WATER) {
// 2x for each attacking type and one more 2x
// since freeze-dry is always 2x effective on water
effectiveness *= 2 * 2 ** attackingTypes.length;
} else {
for (const aType of attackingTypes) {
effectiveness *= singleTypeEffectiveness(aType, dType, options);
}
}
}
if (effectiveness === 0) return [0, 1];
const numeratorExponent = Math.log2(effectiveness);
const denominatorExponent = attackingTypes.length * defendingTypes.length;
return [
2 ** Math.max(0, numeratorExponent - denominatorExponent),
2 ** Math.max(0, denominatorExponent - numeratorExponent)
];
};
示例3: castArray
store.subscribe(({ type }, state) => {
if (hasOwn(saveOn, type)) {
const paths = castArray(saveOn[type]);
for (const [path, value] of zip(paths, at(state, paths))) {
if (path === undefined) continue;
const stringifiedValue = JSON.stringify(value);
try {
storage.setItem(prefixKey(path), stringifiedValue);
} catch {
// this can sometimes throw based on the spec
}
}
}
});
示例4: parseModuleConfig
function parseModuleConfig(serialized: string | string[] | null): ModuleLessonConfig {
const config: ModuleLessonConfig = {};
if (!serialized) return config;
castArray(serialized).forEach((serializedModule) => {
serializedModule.split(LESSON_SEP).forEach((lesson) => {
const [lessonTypeAbbr, classNo] = lesson.split(LESSON_TYPE_SEP);
const lessonType = LESSON_ABBREV_TYPE[lessonTypeAbbr];
// Ignore unparsable/invalid keys
if (!lessonType) return;
config[lessonType] = classNo;
});
});
return config;
}
示例5: createMemoryHistory
export default function createHistory<T>(
initialEntries: HistoryEntry | Readonly<HistoryEntry[]> = '/',
matchParams: MatchShape = {},
): RouteComponentProps<T> {
const entries = _.castArray(initialEntries);
const history = createMemoryHistory({ initialEntries: entries as any });
const { params = {}, isExact = true } = matchParams;
const match = {
params,
isExact,
path: entries[0],
url: entries[0],
} as any;
return {
history,
match,
location: history.location,
};
}
示例6:
return promise.then(() => {
// Simple case. Value in url matches existing options text or value.
let option: any = _.find(variable.options, op => {
return op.text === urlValue || op.value === urlValue;
});
// No luck either it is array or value does not exist in the variables options.
if (!option) {
let defaultText = urlValue;
const defaultValue = urlValue;
if (_.isArray(urlValue)) {
// Multiple values in the url. We construct text as a list of texts from all matched options.
defaultText = urlValue.reduce((acc, item) => {
const t: any = _.find(variable.options, { value: item });
if (t) {
acc.push(t.text);
} else {
acc.push(item);
}
return acc;
}, []);
}
// It is possible that we did not match the value to any existing option. In that case the url value will be
// used anyway for both text and value.
option = { text: defaultText, value: defaultValue };
}
if (variable.multi) {
// In case variable is multiple choice, we cast to array to preserve the same behaviour as when selecting
// the option directly, which will return even single value in an array.
option = { ...option, value: _.castArray(option.value) };
}
return variable.setValue(option);
});
示例7: dismiss
public dismiss(alert: Array<Alert>|Alert): Promise<any> {
return this.middlewareClient.callRpcMethod('alert.dismiss', _.map(_.castArray(alert), 'id'));
}
示例8:
const queryParams = _.transform(req.query, (acc, value, key) => {
for (const val of _.castArray(value)) {
acc.push(`${key}=${val}`);
}
}, []);
示例9:
_.mapValues(ops, relations => {
return _.castArray(relations).map(relation =>
_.isObject(relation) ? relation : { value: relation },
);
}),
示例10: getRoles
public getRoles(req: express.Request): Array<string> {
const roleKey = this.options.rolesKey || 'roles';
return _.castArray(_.get(req.user, roleKey, []));
}