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


TypeScript lodash.isNil函数代码示例

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


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

示例1: traversal

  /**
  * collection traversal - Performs a traversal starting from the given
  * startVertex and following edges contained in this edge collection.
  *
  * @param {String} collectionName collection name
  * @param  {String | String[]} startVertex Start vertex or vertices.
  * This can be either the _id of a document in the database,
  * the _key of an edge in the collection, or a document
  * (i.e. an object with an _id or _key property).
  * @param  {any} opts opts.direction opts.filter, opts.visitor,
  * opts.init, opts.expander, opts.sort
  * @return  {[Object]} edge traversal path
  */
  async traversal(startVertex: string | string[], opts: any, collectionName?: string,
    edgeName?: string, data_flag?: boolean, path_flag?: boolean,
    aql?: boolean): Promise<Object> {
    let collection;
    let traversedData;
    if (_.isNil(startVertex)) {
      throw new Error('missing start vertex name');
    }
    if (opts.lowest_common_ancestor) {
      return this.findTreesCommonAncestor(startVertex as string[],
        collectionName, edgeName);
    }

    let response: any = {
      vertex_fields: [],
      data: {},
      paths: {}
    };
    if (aql && aql == true) {
      // get all the first level childrens for the start vertex
      let result = await this.getAllChildrenNodes(startVertex as string, edgeName);
      let finalResponse = [];
      for (let item of result._result) {
        finalResponse.push(_.omit(item, ['_key', '_id', '_rev']));
      }
      response.data.value = Buffer.from(JSON.stringify(finalResponse));
      return response;
    }

    const vertex = startVertex as string;
    if (_.isArray(vertex)) {
      throw new Error('Invalid number of starting vertices for traversal: ' + vertex.length);
    }
    for (let key in opts) {
      if (_.isEmpty(opts[key])) {
        delete opts[key];
      }
    }

    if (opts && opts.filter) {
      opts.filter = this.traversalFilter(opts.filter);
    } else if (opts && opts.expander) {
      opts.expander = this.traversalExpander(opts.expander);
    }

    if (!opts) {
      // make outbound traversal by default if not provided
      opts = {};
      opts.direction = 'outbound';
    }

    try {
      if (collectionName) {
        collection = this.graph.edgeCollection(collectionName);
        traversedData = await collection.traversal(vertex, opts);
      } else {
        traversedData = await this.graph.traversal(vertex, opts);
      }
    } catch (err) {
      throw { code: err.code, message: err.message };
    }
    let encodedData = new Set<Object>();
    if (data_flag) {
      if (traversedData.visited && traversedData.visited.vertices) {
        traversedData.visited.vertices = this.arrUnique(traversedData.visited.vertices);
        for (let vertice of traversedData.visited.vertices) {
          response.vertex_fields.push(_.pick(vertice, ['_id', '_key', '_rev', 'id']));
          encodedData.add(_.omit(vertice, ['_key', '_rev']));
        }
        response.data.value = encodeMessage(Array.from(encodedData));
      }
    }

    if (path_flag) {
      if (traversedData.visited && traversedData.visited.paths) {
        traversedData.visited.paths = this.arrUnique(traversedData.visited.paths);
        const encodedPaths = encodeMessage(traversedData.visited.paths);
        response.paths.value = encodedPaths;
      }
    }

    return response;
  }
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:96,代码来源:graph.ts

示例2: showTop

  private async showTop(opts) {
    let sorted: Array<{username: string, value: number}> = [];
    let message;
    let i = 0;
    const type = opts.parameters;

    // count ignored users
    const _total = 10 + getIgnoreList().length + 2; // 2 for bot and broadcaster

    moment.locale(global.lib.translate.lang);

    switch (type) {
      case TYPE.TIME:
        sorted = [];
        for (const user of (await global.db.engine.find('users.watched', { _sort: 'watched', _sum: 'watched', _total, _group: 'id' }))) {
          sorted.push({ username: await global.users.getNameById(user._id), value: user.watched });
        }
        message = global.translate('systems.top.time').replace(/\$amount/g, 10);
        break;
      case TYPE.TIPS:
        const users = {};
        const tips = await global.db.engine.find('users.tips');

        message = global.translate('systems.top.tips').replace(/\$amount/g, 10);
        for (const tip of tips) {
          const username = await global.users.getNameById(tip.id);
          if (_.isNil(users[username])) {
            users[username] = { username, value: 0 };
          }
          users[username].value += global.currency.exchange(tip.amount, tip.currency, global.currency.settings.currency.mainCurrency);
        }
        sorted = _.orderBy(users, 'value', 'desc');
        break;
      case TYPE.POINTS:
        if (!global.systems.points.isEnabled()) {
          return;
        }

        sorted = [];
        for (const user of (await global.db.engine.find('users.points', { _sort: 'points', _sum: 'points', _total, _group: 'id' }))) {
          sorted.push({ username: await global.users.getNameById(user._id), value: user.points });
        }
        message = global.translate('systems.top.points').replace(/\$amount/g, 10);
        break;
      case TYPE.MESSAGES:
        sorted = [];
        for (const user of (await global.db.engine.find('users.messages', { _sort: 'messages', _sum: 'messages', _total, _group: 'id' }))) {
          sorted.push({ username: await global.users.getNameById(user._id), value: user.messages });
        }
        message = global.translate('systems.top.messages').replace(/\$amount/g, 10);
        break;
      case TYPE.FOLLOWAGE:
        sorted = [];
        for (const user of (await global.db.engine.find('users', { is: { follower: true }, _sort: '-time.follow', _total }))) {
          sorted.push({ username: user.username, value: user.time.follow });
        }
        message = global.translate('systems.top.followage').replace(/\$amount/g, 10);
        break;
      case TYPE.SUBAGE:
        sorted = [];
        for (const user of (await global.db.engine.find('users', { is: { subscriber: true }, _sort: '-time.subscribed_at', _total }))) {
          sorted.push({ username: user.username, value: user.time.subscribed_at });
        }
        message = global.translate('systems.top.subage').replace(/\$amount/g, 10);
        break;
      case TYPE.BITS:
        sorted = [];
        for (const user of (await global.db.engine.find('users.bits', { _sort: 'amount', _sum: 'amount', _total, _group: 'id' }))) {
          sorted.push({ username: await global.users.getNameById(user._id), value: user.amount });
        }
        message = global.translate('systems.top.bits').replace(/\$amount/g, 10);
        break;
      case TYPE.GIFTS:
        sorted = [];
        for (const user of (await global.db.engine.find('users', { _sort: 'custom.subgiftCount', _total }))) {
          sorted.push({ username: user.username, value: user.custom.subgiftCount });
        }
        message = global.translate('systems.top.gifts').replace(/\$amount/g, 10);
        break;
    }

    if (sorted.length > 0) {
      // remove ignored users
      const ignored: string[] = [];
      for (const user of sorted) {
        if (isIgnored(user.username)) {
          ignored.push(user.username);
        }
      }

      _.remove(sorted, (o) => _.includes(ignored, o.username));
      // remove broadcaster and bot accounts
      _.remove(sorted, (o) => _.includes([getChannel(), global.oauth.settings.bot.username.toLowerCase()], o.username));
      sorted = _.chunk(sorted, 10)[0];

      for (const user of sorted) {
        message += (i + 1) + '. ' + (global.tmi.settings.chat.showWithAt ? '@' : '') + (user.username || 'unknown') + ' - ';
        switch (type) {
          case TYPE.TIME:
            message += (user.value / 1000 / 60 / 60).toFixed(1) + 'h';
//.........这里部分代码省略.........
开发者ID:sogehige,项目名称:SogeBot,代码行数:101,代码来源:top.ts

示例3: conditionalAttrFn

function conditionalAttrFn(node: any, attr: any, value: any, skipValue?: any) {
  if (!_.isNil(value) && (skipValue === undefined || value !== skipValue)) {
    node.setAttributeNS(ANDROID_NS, attr, value);
  }
}
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:5,代码来源:AvdSerializer.ts

示例4: constructor

  constructor(server: Server, config: any, logger: Logger, events: Events) {
    if (_.isNil(events)) {
      if (logger.error) {
        logger.error('No Kafka client was provided. Disabling all commands.');
        return;
      }
    }
    if (!_.has(config, 'server.services')) {
      throw new Error('missing config server.services');
    }

    this.config = config;
    this.logger = logger;

    if (!_.has(this.config, 'events')
      || !_.has(this.config.events, 'kafka')
      || !_.has(this.config.events.kafka, 'topics')
      || !_.has(this.config.events.kafka.topics, 'command')) {
      throw new Error('Commands topic configuration was not provided.');
    }

    this.kafkaEvents = events;

    // Health
    this.health = {
      status: ServingStatus.UNKNOWN,
    };
    this.service = {};
    const service = this.service;
    const health = this.health;
    _.forEach(config.server.services, (serviceCfg, serviceName) => {
      service[serviceName] = {
        bound: false,
        transport: {},
      };
    });
    server.on('bound', (serviceName) => {
      service[serviceName].bound = true;
      health.status = ServingStatus.NOT_SERVING;
    });
    server.on('serving', (transports) => {
      health.status = ServingStatus.SERVING;
      _.forEach(transports, (transport, transportName) => {
        _.forEach(service, (srv, serviceName) => {
          service[serviceName].transport[transportName] = ServingStatus.SERVING;
        });
      });
    });
    server.on('stopped', (transports) => {
      health.status = ServingStatus.NOT_SERVING;
      _.forEach(transports, (transport, transportName) => {
        _.forEach(service, (srv, serviceName) => {
          service[serviceName].transport[transportName] = ServingStatus.NOT_SERVING;
        });
      });
    });

    // list of available commands
    this.commands = {
      reset: this.reset,
      restore: this.restore,
      reconfigure: this.reconfigure,
      health_check: this.check,
      version: this.version
    };
    const topicCfg = config.events.kafka.topics.command;
    this.commandTopic = events.topic(topicCfg.topic);
    // check for buffer fields
    this.bufferedCollection = new Map<string, string>();
    if (this.config.fieldHandlers && this.config.fieldHandlers.bufferFields) {
      for (let bufferedCollection in this.config.fieldHandlers.bufferFields) {
        this.bufferedCollection.set(bufferedCollection,
          this.config.fieldHandlers.bufferFields[bufferedCollection]);
      }
      this.logger.info('Buffered collections are:', this.bufferedCollection);
    }
  }
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:77,代码来源:index.ts

示例5: integer

export function integer(int?: number) {
  return somethingLike<number>(isNil(int) ? 13 : int)
}
开发者ID:pact-foundation,项目名称:pact-js,代码行数:3,代码来源:matchers.ts

示例6:

export const rangeLogRequestKey = (req: api.RangeLogRequestMessage): string =>
  _.isNil(req.range_id) ? "none" : req.range_id.toString();
开发者ID:jordanlewis,项目名称:cockroach,代码行数:2,代码来源:apiReducers.ts

示例7: isApplicable

 public isApplicable(target): boolean {
     return _.isNil(target.query) && !_.isNil(target.horAggregator);
 }
开发者ID:BrandonArp,项目名称:kairosdb-datasource,代码行数:3,代码来源:legacy_target_converter.ts

示例8:

 .filter((value) => !_.isNil(value));
开发者ID:BrandonArp,项目名称:kairosdb-datasource,代码行数:1,代码来源:tags_select.ts

示例9: isEmpty

 static isEmpty(value) {
     return _.isNil(value) || value === '' || ((_.isArray(value) || _.isPlainObject(value)) && _.isEmpty(value));
 }
开发者ID:vruden,项目名称:node-validator,代码行数:3,代码来源:async-default-value-validator.ts

示例10: _activate

function _activate(context: vscode.ExtensionContext) {
    let settings = Settings.getInstance();
    settings.extensionRoot = context.extensionPath;
    settings.workspaceRoot = vscode.workspace.rootPath;
    settings.loadSettings(vscode.workspace.getConfiguration("gerrit"));
    if (!isNil(settings.active) && !settings.active) {
        return;
    }
    vscode.workspace.onDidChangeConfiguration(() => settings.loadSettings(vscode.workspace.getConfiguration("gerrit")));

    let fileContainer = FileServiceClient.getInstance();
    context.subscriptions.push(fileContainer.startServer());

    let commands: vscode.Disposable[] = [];
    controller = new Controller();

    commands.push(
        vscode.commands.registerCommand("gerrit.stageAll", () => controller.stageAll())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.stageCurrentFile", () => controller.stageCurrentFile())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.stageFile", () => controller.stageFile())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.resetAll", () => controller.resetAll())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.resetCurrentFile", () => controller.resetCurrentFile())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.resetFile", () => controller.resetFile())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.cleanAll", () => controller.cleanAll())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.cleanCurrentFile", () => controller.cleanCurrentFile())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.checkoutBranch", () => controller.checkoutBranch())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.checkoutRevision", () => controller.checkoutRevision())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.cherrypickRevision", () => controller.cherrypickRevision())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.cherrypickContinue", () => controller.cherrypickContinue())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.commit", () => controller.commit())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.commitAmend", () => controller.commitAmend())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.pushBranch", () => controller.push())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.draftBranch", () => controller.draft())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.rebaseBranch", () => controller.rebase())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.rebaseContinue", () => controller.rebaseContinue())
    );
    commands.push(
        vscode.commands.registerCommand("gerrit.log", () => controller.toggleLog())
    );

    context.subscriptions.concat(commands);
}
开发者ID:KnisterPeter,项目名称:gerrit-vscode,代码行数:76,代码来源:extension.ts


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