当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.isArray函数代码示例

本文整理汇总了TypeScript中lodash.isArray函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isArray函数的具体用法?TypeScript isArray怎么用?TypeScript isArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了isArray函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

	errorFn = function(param, _type) {
		if (_.isPlainObject(param))
			param = [param];
		else if (!_.isArray(param)) {
			param = [{
				errCode: 500
			}];
		}

		let
			topCode = [],
			topMessage = [],
			errors = [];

		param.forEach(function(err) {
			let
				difine = formatErrors[err.code] || formatErrors['1'];

			topCode.push(difine.parent.code);
			topMessage.push(difine.parent.message);

			errors.push({
				code: parseInt(err.code),
				message: difine.message,
				path: err.path,
				value: err.value
			});
		});

		let
			data = {
				code: topCode.length > 1 ? topCode.join(',') : parseInt(topCode[0]),
				message: topMessage.join(','),
				errors: errors
			};

		return _type === 'lite' ? errors : Promise.reject(data);
	};
开发者ID:goumang2010,项目名称:NetTxtNote,代码行数:38,代码来源:errors.ts

示例2: validateFlowSchema

export function validateFlowSchema(flow: Flow) {
  // const errorPrefix = `[Flow] Invalid flow "${flow && flow.location}"`
  const errorPrefix = `[Flow] Invalid flow "${flow}"`

  if (!flow || !_.isObjectLike(flow)) {
    return 'Invalid JSON flow schema'
  }

  if (!flow.version || !_.isString(flow.version)) {
    return `${errorPrefix}, expected valid version but found none`
  }

  if (!flow.version.startsWith('0.')) {
    return `${errorPrefix}, unsupported version of the schema "${flow.version}"`
  }

  if (!_.isString(flow.startNode)) {
    return `${errorPrefix}, expected valid 'startNode'`
  }

  if (!_.isArray(flow.nodes)) {
    return `${errorPrefix}, expected 'nodes' to be an array of nodes`
  }

  if (!_.find(flow.nodes, { name: flow.startNode })) {
    return `${errorPrefix}, expected 'startNode' to point to a valid node name`
  }

  if (flow.catchAll && flow.catchAll.onEnter) {
    return `${errorPrefix}, "catchAll" does not support "onEnter"`
  }

  for (const node of flow.nodes) {
    if (!_.isString(node.id) || node.id.length <= 3) {
      return `${errorPrefix}, expected node ${node.id} (${node.name}) to have a valid id`
    }
  }
}
开发者ID:alexsandrocruz,项目名称:botpress,代码行数:38,代码来源:validator.ts

示例3: selectOptionsForCurrentValue

  selectOptionsForCurrentValue(variable) {
    var i, y, value, option;
    var selected: any = [];

    for (i = 0; i < variable.options.length; i++) {
      option = variable.options[i];
      option.selected = false;
      if (_.isArray(variable.current.value)) {
        for (y = 0; y < variable.current.value.length; y++) {
          value = variable.current.value[y];
          if (option.value === value) {
            option.selected = true;
            selected.push(option);
          }
        }
      } else if (option.value === variable.current.value) {
        option.selected = true;
        selected.push(option);
      }
    }

    return selected;
  }
开发者ID:shirish87,项目名称:grafana,代码行数:23,代码来源:variable_srv.ts

示例4: fromJSON

  private fromJSON (s: IDocumentObject) {
    if (!isDocumentObject(s)) {
      throw ErrInvalidJSON
    }

    if (typeof s.data !== 'undefined') {
      this._data = _.isArray(s.data)
        ? s.data
        : [ s.data ]
    }

    if (_.isError(s.error)) {
      this.error = s.error
    } else if (_.isString(s.error)) {
      this.error = new Error(s.error)
    }

    this._meta = s.meta
    this._links = s.links
    this._included = s.included

    this.validate()
  }
开发者ID:perpengt,项目名称:jsonapi,代码行数:23,代码来源:document.ts

示例5:

  let requests = pkgNames.filter(pkgName => {
    let pkgPath = config.getPath('npm.src', pkgName, 'package.json')

    if (!fs.existsSync(pkgPath)) {
      return false
    }

    let pkgData = fs.readJsonSync(pkgPath)

    // 验证 min-cli 开发的 小程序组件
    if (!_.get(pkgData, 'minConfig.component') && !_.get(pkgData, 'config.min.component')) {
      return false
    }

    let entryConfig: string[] = _.get(pkgData, 'minConfig.entry')
    if (_.isArray(entryConfig) && entryConfig.length) {
        entryConfig.forEach(entry => {
          entries.push(pkgName + '/' + entry)
      })
      return false
    }
    return true
  })
开发者ID:bbxyard,项目名称:bbxyard,代码行数:23,代码来源:tool.ts

示例6: addDashboardImpression

  addDashboardImpression(impression) {
    var impressions = [];
    if (store.exists("dashboard_impressions")) {
      impressions = JSON.parse(store.get("dashboard_impressions"));
      if (!_.isArray(impressions)) {
        impressions = [];
      }
    }

    impressions = impressions.filter((imp) => {
      return impression.meta.slug !== imp.slug;
    });

    impressions.unshift({
      title: impression.dashboard.title,
      slug: impression.meta.slug
    });

    if (impressions.length > 20) {
      impressions.shift();
    }
    store.set("dashboard_impressions", JSON.stringify(impressions));
  }
开发者ID:Shi-Liang,项目名称:grafana,代码行数:23,代码来源:impression_store.ts

示例7: createVertex

 /**
  * create a new Vertex with given data.
  *
  * @param  {string} collectionName vertex collection name
  * @param  {Object} data data for vertex
  * @return  {Object} created vertex
  */
 async createVertex(collectionName: string, data: any): Promise<any> {
   if (_.isNil(collectionName)) {
     throw new Error('missing vertex collection name');
   }
   if (_.isNil(data)) {
     throw new Error('missing data for vertex');
   }
   const collection = this.graph.vertexCollection(collectionName);
   let docs = _.cloneDeep(data);
   if (!_.isArray(docs)) {
     docs = [docs];
   }
   _.forEach(docs, (document, i) => {
     docs[i] = sanitizeInputFields(document);
   });
   const results = await collection.save(docs);
   _.forEach(results, (result) => {
     if (result.error === true) {
       throw new Error(result.errorMessage);
     }
   });
   return _.map(docs, sanitizeOutputFields);
 }
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:30,代码来源:graph.ts

示例8: urlJoin

const createUrl = (
    serverAddress: string,
    urlPaths: string | string[],
    pathParameters: { [key: string]: string | number } = {},
    queryParameters: { [key: string]: string | number } = {},
) => {
    let joinedPath = urlJoin(...(lodash.isArray(urlPaths) ? urlPaths : [urlPaths]));

    if (!lodash.isEmpty(pathParameters)) {
        for (const pathParamKey of Object.keys(pathParameters)) {
            const re = new RegExp(`:${pathParamKey}`);
            joinedPath = joinedPath.replace(re, pathParameters[pathParamKey].toString());
        }
    }

    let url = urlJoin(serverAddress, joinedPath);

    if (!lodash.isEmpty(queryParameters)) {
        url = urlJoin(url, { query: queryParameters });
    }

    return url;
};
开发者ID:athrunsun,项目名称:oh-my-stars,代码行数:23,代码来源:url.ts

示例9: upsert

  /**
   * Find each document based on it's key and update it.
   * If the document does not exist it will be created.
   *
   * @param  {String} collection Collection name
   * @param {Object|Array.Object} documents
   */
  async upsert(collectionName: string, documents: any): Promise<any> {
    if (_.isNil(collectionName) ||
      !_.isString(collectionName) || _.isEmpty(collectionName)) {
      throw new Error('invalid or missing collection argument');
    }
    if (_.isNil(documents)) {
      throw new Error('invalid or missing documents argument');
    }
    let docs = _.cloneDeep(documents);
    if (!_.isArray(documents)) {
      docs = [documents];
    }
    _.forEach(docs, (document, i) => {
      docs[i] = sanitizeInputFields(document);
    });
    const collection = this.db.collection(collectionName);
    const queryTemplate = aql`FOR document in ${docs} UPSERT { _key: document._key }
      INSERT document UPDATE document IN ${collection} return NEW`;

    const res = await query(this.db, collectionName, queryTemplate);
    const newDocs = await res.all();
    return _.map(newDocs, sanitizeOutputFields);
  }
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:30,代码来源:base.ts

示例10: Error

export const checkParams = (services: any[],
  models: any[],
  registers: any[],
  decorations: Decoration[],
  routesConfig: any) => {
  const areInitables = (targets: any[], message) => {
    if (!isArray(targets)) {
      throw new Error(`${message}`);
    }
    targets.forEach(target => {
      if (!isFunction(target.init)) {
        throw new Error(`${message}.init is not a function for ${target}`);
      }
    });
  };
  const areCallables = (targets: any[], message) => {
    if (!isArray(targets)) {
      throw new Error(`${message}`);
    }
    targets.forEach(target => {
      if (!isFunction(target)) {
        throw new Error(`${message} is not a function, got: ${JSON.stringify(target)}`);
      }
    });
  };
  areInitables(services, 'services');
  areInitables(models, 'models');
  areCallables(registers, 'registers');
  if (!isArray(decorations)) {
    throw new Error('decorations');
  }
  areCallables(decorations.map(decoration => decoration.method), 'decorations');
  if (!isPlainObject(routesConfig)) {
    throw new Error('routes');
  }
  return true;
};
开发者ID:MarcDeletang,项目名称:bedrock,代码行数:37,代码来源:checks.ts


注:本文中的lodash.isArray函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。