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


TypeScript lodash.transform函數代碼示例

本文整理匯總了TypeScript中lodash.transform函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript transform函數的具體用法?TypeScript transform怎麽用?TypeScript transform使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了transform函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: disabledAxisMap

export function disabledAxisMap(h: McuParams): Record<Xyz, boolean> {
  return transform<boolean, Record<Xyz, boolean>>(
    enabledAxisMap(h),
    (d: Record<Xyz, boolean>[], value: boolean, key: Xyz) => {
      d[0][key] = !value;
    }, [{ x: false, y: false, z: false }])[0];
}
開發者ID:FarmBot,項目名稱:Farmbot-Web-API,代碼行數:7,代碼來源:axis_tracking_status.ts

示例2: function

const handleV2CoinSpecificREST = function(req, res, next) {
  const method = req.method;
  const bitgo = req.bitgo;

  try {
    const coin = bitgo.coin(req.params.coin);
    const coinURL = coin.url(createAPIPath(req));
    return redirectRequest(bitgo, method, coinURL, req, next);
  } catch (e) {
    if (e instanceof errors.UnsupportedCoinError) {
      const queryParams = _.transform(req.query, (acc, value, key) => {
        for (const val of _.castArray(value)) {
          acc.push(`${key}=${val}`);
        }
      }, []);
      const baseUrl = bitgo.url(req.baseUrl.replace(/^\/api\/v2/, ''), 2);
      const url = _.isEmpty(queryParams) ? baseUrl : `${baseUrl}?${queryParams.join('&')}`;

      debug(`coin ${req.params.coin} not supported, attempting to handle as a coinless route with url ${url}`);
      return redirectRequest(bitgo, method, url, req, next);
    }

    throw e;
  }
};
開發者ID:BitGo,項目名稱:BitGoJS,代碼行數:25,代碼來源:clientRoutes.ts

示例3: difference

export function difference (obj: _.Dictionary<any>, base: _.Dictionary<any>) {
  return _.transform(obj, (result, value, key) => {
    if (!_.isEqual(value, base[key])) {
      result[key] = _.isObject(value) && _.isObject(base[key]) ? difference(value, base[key]) : value
    }
  })
}
開發者ID:perpengt,項目名稱:jsonapi,代碼行數:7,代碼來源:utils.ts

示例4: constructor

  /**
   * Server is a gRPC transport provider for serving.
   *
   * @param {Object} config Configuration object.
   * Requires properties:addr,package,proto,service
   * Optional properties: credentials.ssl.certs
   */
  constructor(config: any, logger: any) {
    if (_.isNil(logger)) {
      throw new Error('gRPC server transport provider requires a logger');
    }
    if (!_.has(config, 'addr')) {
      throw new Error('server is missing addr config field');
    }
    if (!_.has(config, 'services')) {
      throw new Error('server is missing services config field');
    }
    this.config = config;
    this.logger = logger;

    // console['error'] = logger.debug;
    // gRPC logger
    grpc.setLogger(console);

    this.server = new grpc.Server();

    // build protobuf
    const protoRoot = config.protoRoot || path.join(process.cwd(), 'protos');
    if (_.isNil(protoRoot) || _.size(protoRoot) === 0) {
      throw new Error('config value protoRoot is not set');
    }
    const protos = config.protos;
    if (_.isNil(protos) || _.size(protos) === 0) {
      throw new Error('config value protos is not set');
    }
    this.logger.verbose(`gRPC Server loading protobuf files from root ${protoRoot}`,  { protos });


    const proto = [];
    for (let i = 0; i < protos.length; i++) {
      const filePath = { root: protoRoot, file: protos[i] };
      this.proto = grpc.load(filePath, 'proto', {
        longsAsStrings: false
      });
      proto[i] = this.proto;
    }

    let k = 0;
    this.service = _.transform(this.config.services, (service: any, protobufServiceName: string, serviceName: string) => {
      const serviceDef = _.get(proto[k], protobufServiceName);
      if (_.isNil(serviceDef)) {
        throw new Error(`Could not find ${protobufServiceName} protobuf service`);
      }
      _.set(service, serviceName, serviceDef.service);
      k++;
      logger.verbose('gRPC service loaded', serviceName);
    });
    this.name = NAME;
  }
開發者ID:restorecommerce,項目名稱:chassis-srv,代碼行數:59,代碼來源:index.ts

示例5: flattenObject

export function flattenObject(obj: any) {
  return _.transform(obj, function (result, value, key) {
    if (_.isObject(value) && !_.isArray(value)) {
      const flatMap = _.mapKeys(flattenObject(value), (_mvalue, mkey) => {
        return `${key}.${mkey}`;
      });
      _.assign(result, flatMap);
    } else {
      result[key] = value;
    }

    return result;
  }, {});
}
開發者ID:qwb0920,項目名稱:ext-ionic,代碼行數:14,代碼來源:util.ts

示例6: async

    const checkPrivilegesAtResources = async (
      resources: string[],
      privilegeOrPrivileges: string | string[]
    ): Promise<CheckPrivilegesAtResourcesResponse> => {
      const privileges = Array.isArray(privilegeOrPrivileges)
        ? privilegeOrPrivileges
        : [privilegeOrPrivileges];
      const allApplicationPrivileges = uniq([actions.version, actions.login, ...privileges]);

      const hasPrivilegesResponse: HasPrivilegesResponse = await callWithRequest(
        request,
        'shield.hasPrivileges',
        {
          body: {
            applications: [
              {
                application,
                resources,
                privileges: allApplicationPrivileges,
              },
            ],
          },
        }
      );

      validateEsPrivilegeResponse(
        hasPrivilegesResponse,
        application,
        allApplicationPrivileges,
        resources
      );

      const applicationPrivilegesResponse = hasPrivilegesResponse.application[application];

      if (hasIncompatibileVersion(applicationPrivilegesResponse)) {
        throw new Error(
          'Multiple versions of Kibana are running against the same Elasticsearch cluster, unable to authorize user.'
        );
      }

      return {
        hasAllRequested: hasPrivilegesResponse.has_all_requested,
        username: hasPrivilegesResponse.username,
        // we need to filter out the non requested privileges from the response
        resourcePrivileges: transform(applicationPrivilegesResponse, (result, value, key) => {
          result[key!] = pick(value, privileges);
        }),
      };
    };
開發者ID:spalger,項目名稱:kibana,代碼行數:49,代碼來源:check_privileges.ts

示例7: convert

export function convert(obj) {
    return _.transform(obj, function (result, value, key) {
        if (_.isObject(value)) {
            let flatMap = _.mapKeys(convert(value), function (mvalue, mkey) {
                if (_.isArray(value)) {
                    let index = mkey.indexOf('.');
                    if (-1 !== index) {
                        return `${key}[${mkey.slice(0, index)}]${mkey.slice(index)}`;
                    }
                    return `${key}[${mkey}]`;
                }
                return `${key}.${mkey}`;
            });

            _.assign(result, flatMap);
        } else {
            result[key] = value;
        }

        return result;
    }, {});
}
開發者ID:richie5um,項目名稱:FlattenJS,代碼行數:22,代碼來源:flatten.ts

示例8: checkPrivilegesWithRequest

  return function checkPrivilegesWithRequest(request: Record<string, any>): CheckPrivileges {
    const checkPrivilegesAtResources = async (
      resources: string[],
      privilegeOrPrivileges: string | string[]
    ): Promise<CheckPrivilegesAtResourcesResponse> => {
      const privileges = Array.isArray(privilegeOrPrivileges)
        ? privilegeOrPrivileges
        : [privilegeOrPrivileges];
      const allApplicationPrivileges = uniq([actions.version, actions.login, ...privileges]);

      const hasPrivilegesResponse: HasPrivilegesResponse = await callWithRequest(
        request,
        'shield.hasPrivileges',
        {
          body: {
            applications: [
              {
                application,
                resources,
                privileges: allApplicationPrivileges,
              },
            ],
          },
        }
      );

      validateEsPrivilegeResponse(
        hasPrivilegesResponse,
        application,
        allApplicationPrivileges,
        resources
      );

      const applicationPrivilegesResponse = hasPrivilegesResponse.application[application];

      if (hasIncompatibileVersion(applicationPrivilegesResponse)) {
        throw new Error(
          'Multiple versions of Kibana are running against the same Elasticsearch cluster, unable to authorize user.'
        );
      }

      return {
        hasAllRequested: hasPrivilegesResponse.has_all_requested,
        username: hasPrivilegesResponse.username,
        // we need to filter out the non requested privileges from the response
        resourcePrivileges: transform(applicationPrivilegesResponse, (result, value, key) => {
          result[key!] = pick(value, privileges);
        }),
      };
    };

    const checkPrivilegesAtResource = async (
      resource: string,
      privilegeOrPrivileges: string | string[]
    ) => {
      const { hasAllRequested, username, resourcePrivileges } = await checkPrivilegesAtResources(
        [resource],
        privilegeOrPrivileges
      );
      return {
        hasAllRequested,
        username,
        privileges: resourcePrivileges[resource],
      };
    };

    return {
      async atSpace(spaceId: string, privilegeOrPrivileges: string | string[]) {
        const spaceResource = ResourceSerializer.serializeSpaceResource(spaceId);
        return await checkPrivilegesAtResource(spaceResource, privilegeOrPrivileges);
      },
      async atSpaces(spaceIds: string[], privilegeOrPrivileges: string | string[]) {
        const spaceResources = spaceIds.map(spaceId =>
          ResourceSerializer.serializeSpaceResource(spaceId)
        );
        const { hasAllRequested, username, resourcePrivileges } = await checkPrivilegesAtResources(
          spaceResources,
          privilegeOrPrivileges
        );
        return {
          hasAllRequested,
          username,
          // we need to turn the resource responses back into the space ids
          spacePrivileges: transform(resourcePrivileges, (result, value, key) => {
            result[ResourceSerializer.deserializeSpaceResource(key!)] = value;
          }),
        };
      },
      async globally(privilegeOrPrivileges: string | string[]) {
        return await checkPrivilegesAtResource(GLOBAL_RESOURCE, privilegeOrPrivileges);
      },
    };
  };
開發者ID:spalger,項目名稱:kibana,代碼行數:93,代碼來源:check_privileges.ts

示例9: extractSymbols

export function extractSymbols(
  element: any,
  document: string,
  documentLines: string[],
  symbolsType: RefractSymbolMap[],
): SymbolInformation[] {

  const queryResults = query(element, symbolsType);

  return lodash.transform(queryResults, (result, queryResult) => {

    /*
      WARNING: This might be your reaction when you'll look into this code: 😱
      Thing is there is no really source map here and I do not want to solve this
      thing in this release. The long term idea would be to wait till the underlying
      parser will be updated to generate sourcemaps on generated content as well
      and everybody will be happy; till that moment, please bear with me.
    */

    let sourceMap;
    ['meta.title.attributes.sourceMap',
      'attributes.href.attributes.sourceMap',
      (qs) => query(qs, [{ query: { attributes: { method: {} } }, symbolKind: 0 }]),
    ].some((path: string | Function): boolean => {
      if (typeof (path) === 'function') {
        sourceMap = lodash.get((path as Function)(queryResult)[0], 'attributes.method.attributes.sourceMap');
        return true;
      } else {
        if (lodash.has(queryResult, path)) {
          sourceMap = lodash.get(queryResult, path);
          return true;
        }
      }
    });

    const lineReference = createLineReferenceFromSourceMap(
      sourceMap,
      document,
      documentLines,
    );

    let description = '';

    ['meta.title.content',
      'attributes.href.content',
      (qs) => query(qs, [{ query: { attributes: { method: {} } }, symbolKind: 0 }]),
    ].some((path: string | Function): boolean => {
      if (typeof (path) === 'function') {
        description = decodeURI(lodash.get((path as Function)(queryResult)[0], 'attributes.method.content'));
        return true;
      } else {
        if (lodash.has(queryResult, path)) {
          description = decodeURI(lodash.get(queryResult, path));
          return true;
        }
      }

    });

    if (!lodash.isEmpty(lineReference)) {
      result.push(SymbolInformation.create(
        description,
        queryResult.symbolKind,
        Range.create(
          lineReference.startRow,
          lineReference.startIndex,
          lineReference.endRow,
          lineReference.endIndex,
        ),
        null,
        queryResult.container));

    }

  });

}
開發者ID:XVincentX,項目名稱:vscode-apielements,代碼行數:77,代碼來源:refractUtils.ts

示例10:

 (sentence_answers, sentence_answer, sentence_num) => sentence_answers[sentence_num] = _.transform(sentence_answer,
     (word_answers, word_answer, word_index) => word_answers[word_index] = {
         word: word_answer.word,
         valid: state.sentences[sentence_num].words[+word_index] === word_answer.word
     }
 )
開發者ID:pocmanu,項目名稱:angular2-seed-advanced,代碼行數:6,代碼來源:missing-word-exercise.reducer.ts


注:本文中的lodash.transform函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。