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


TypeScript util.isString函数代码示例

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


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

示例1: fieldDef

export function fieldDef(encQ: EncodingQuery,
    include: PropIndex<boolean> = INCLUDE_ALL,
    replacer: PropIndex<Replacer> = REPLACE_NONE): string {

  if (include.get(Property.AGGREGATE) && isDisabledAutoCountQuery(encQ)) {
    return '-';
  }

  const fn = func(encQ, include, replacer);
  const props = fieldDefProps(encQ, include, replacer);

  let fieldAndParams;
  if (isFieldQuery(encQ)) {
    // field
    fieldAndParams = include.get('field') ? value(encQ.field, replacer.get('field')) : '...';
    // type
    if (include.get(Property.TYPE)) {
      if (isWildcard(encQ.type)) {
        fieldAndParams += ',' + value(encQ.type, replacer.get(Property.TYPE));
      } else {
        const typeShort = ((encQ.type || Type.QUANTITATIVE)+'').substr(0,1);
        fieldAndParams += ',' + value(typeShort, replacer.get(Property.TYPE));
      }
    }
    // encoding properties
    fieldAndParams += props.map((p) => {
      let val = p.value instanceof Array ? '[' + p.value + ']' : p.value;
      return ',' + p.key + '=' + val;
    }).join('');
  } else if (isAutoCountQuery(encQ)) {
    fieldAndParams = '*,q';
  }

  if (!fieldAndParams) {
    return null;
  }
  if (fn) {
    let fnPrefix = isString(fn) ? fn : SHORT_WILDCARD +
      (keys(fn).length > 0 ? JSON.stringify(fn) : '');

    return fnPrefix + '(' + fieldAndParams + ')';
  }
  return fieldAndParams;
}
开发者ID:herrstucki,项目名称:compassql,代码行数:44,代码来源:shorthand.ts

示例2: hash

export function hash(a: any) {
  if (isString(a) || isNumber(a) || isBoolean(a)) {
    return String(a);
  }
  return stringify(a);
}
开发者ID:glimpseio,项目名称:vega-lite,代码行数:6,代码来源:util.ts

示例3: fieldDefProps

/**
 * Return key-value of parameters of field defs
 */
function fieldDefProps(fieldQ: FieldQuery, include: PropIndex<boolean>, replacer: PropIndex<Replacer>) {

  /** Encoding properties e.g., Scale, Axis, Legend */
  const props: {key: string, value: boolean | Object}[] = [];

  // Parameters of function such as bin will be just top-level properties
  if (!isBoolean(fieldQ.bin) && !isShortWildcard(fieldQ.bin)) {
    const bin = fieldQ.bin;
    for (const child in bin) {
      const prop = getEncodingNestedProp('bin', child as EncodingNestedChildProp);
      if (prop && include.get(prop) && bin[child] !== undefined) {
        props.push({
          key: child,
          value: value(bin[child], replacer.get(prop))
        });
      }
    }
    // Sort to make sure that parameter are ordered consistently
    props.sort((a, b) => a.key.localeCompare(b.key));
  }

  for (const parent of [Property.SCALE, Property.SORT, Property.AXIS, Property.LEGEND]) {
    if (!isWildcard(fieldQ.channel) && !PROPERTY_SUPPORTED_CHANNELS[parent][fieldQ.channel as Channel]) {
      continue;
    }

    if (include.get(parent) && fieldQ[parent] !== undefined) {
      const parentValue = fieldQ[parent];
      if (isBoolean(parentValue) || parentValue === null) {
        // `scale`, `axis`, `legend` can be false/null.
        props.push({
          key: parent + '',
          value: parentValue || false // return true or false (false if null)
        });
      } else if (isString(parentValue)) {

        // `sort` can be a string (ascending/descending).
        props.push({
          key: parent + '',
          value: replace(JSON.stringify(parentValue), replacer.get(parent))
        });
      } else {
        let nestedPropChildren = [];
        for (const child in parentValue) {
          const nestedProp = getEncodingNestedProp(parent, child as EncodingNestedChildProp);
          if (nestedProp && include.get(nestedProp) && parentValue[child] !== undefined) {
            nestedPropChildren.push({
              key: child,
              value: value(parentValue[child], replacer.get(nestedProp))
            });
          }
        }

        if(nestedPropChildren.length > 0) {
          const nestedPropObject = nestedPropChildren.sort((a, b) => a.key.localeCompare(b.key))
            .reduce((o, item) => {
              o[item.key] = item.value;
              return o;
            }, {});

          // Sort to make sure that parameter are ordered consistently
          props.push({
            key: parent + '',
            value: JSON.stringify(nestedPropObject)
          });
        }
      }
    }
  }
  return props;
}
开发者ID:herrstucki,项目名称:compassql,代码行数:74,代码来源:shorthand.ts


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