• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript lodash.castArray函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript lodash.chain函数代码示例发布时间:2022-05-25
下一篇:
TypeScript lodash.capitalize函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap