本文整理汇总了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
}
}
}
});
};
开发者ID:Sulcata,项目名称:Sulcata-Damage-Calculator,代码行数:30,代码来源:plugins.ts
示例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)
];
};
开发者ID:Sulcata,项目名称:Sulcata-Damage-Calculator,代码行数:42,代码来源:info.ts
示例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
}
}
}
});
开发者ID:Sulcata,项目名称:Sulcata-Damage-Calculator,代码行数:14,代码来源:plugins.ts
示例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;
}
开发者ID:nusmodifications,项目名称:nusmods,代码行数:16,代码来源:timetables.ts
示例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,
};
}
开发者ID:nusmodifications,项目名称:nusmods,代码行数:21,代码来源:createHistory.ts
示例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);
});
开发者ID:grafana,项目名称:grafana,代码行数:38,代码来源:variable_srv.ts
示例7: dismiss
public dismiss(alert: Array<Alert>|Alert): Promise<any> {
return this.middlewareClient.callRpcMethod('alert.dismiss', _.map(_.castArray(alert), 'id'));
}
开发者ID:mactanxin,项目名称:gui,代码行数:3,代码来源:alert-dao.ts
示例8:
const queryParams = _.transform(req.query, (acc, value, key) => {
for (const val of _.castArray(value)) {
acc.push(`${key}=${val}`);
}
}, []);
开发者ID:BitGo,项目名称:BitGoJS,代码行数:5,代码来源:clientRoutes.ts
示例9:
_.mapValues(ops, relations => {
return _.castArray(relations).map(relation =>
_.isObject(relation) ? relation : { value: relation },
);
}),
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:5,代码来源:operationGraph.ts
示例10: getRoles
public getRoles(req: express.Request): Array<string> {
const roleKey = this.options.rolesKey || 'roles';
return _.castArray(_.get(req.user, roleKey, []));
}
开发者ID:thiagobustamante,项目名称:typescript-rest,代码行数:4,代码来源:passport.ts
注:本文中的lodash.castArray函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论