當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript lodash.castArray函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。