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


TypeScript fp.isString函數代碼示例

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


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

示例1:

export const escapeQueryValue = (val: number | string = ''): string | number => {
  if (isString(val)) {
    return val.replace(/"/g, '\\"');
  }

  return val;
};
開發者ID:,項目名稱:,代碼行數:7,代碼來源:

示例2: get

 Object.keys(sources).reduce<DetailItem[]>((accumulator, source) => {
   const item = get(source, sources);
   if (Array.isArray(item) || isString(item) || isNumber(item)) {
     const field = path ? `${path}.${source}` : source;
     category = field.split('.')[0];
     if (isEmpty(category) && baseCategoryFields.includes(category)) {
       category = 'base';
     }
     return [
       ...accumulator,
       {
         category,
         field,
         values: item,
         originalValue: item,
       } as DetailItem,
     ];
   } else if (isObject(item)) {
     return [
       ...accumulator,
       ...getDataFromHits(item, category || source, path ? `${path}.${source}` : source),
     ];
   }
   return accumulator;
 }, []);
開發者ID:,項目名稱:,代碼行數:25,代碼來源:

示例3: ID

export function ID(gpmlElement) {
  if (gpmlElement.hasOwnProperty("ID")) {
    const { ID } = gpmlElement;
    return isString(ID) ? ID : ID.content;
  } else {
    return gpmlElement.Xref.ID;
  }
}
開發者ID:wikipathways,項目名稱:gpml2pvjson-js,代碼行數:8,代碼來源:ValueConverters.ts

示例4: if

const convertToNumber = (value: object | number | boolean | string): number => {
  if (isNumber(value)) {
    return value;
  } else if (isString(value)) {
    return parseFloat(value);
  } else {
    return NaN;
  }
};
開發者ID:,項目名稱:,代碼行數:9,代碼來源:

示例5: getTimelineIdFromDestination

export const addFieldToTimelineColumns = ({
  upsertColumn = timelineActions.upsertColumn,
  browserFields,
  dispatch,
  result,
}: AddFieldToTimelineColumnsParams): void => {
  const timeline = getTimelineIdFromDestination(result);
  const fieldId = getFieldIdFromDraggable(result);
  const allColumns = getAllFieldsByName(browserFields);
  const column = allColumns[fieldId];

  if (column != null) {
    dispatch(
      upsertColumn({
        column: {
          category: column.category,
          columnHeaderType: 'not-filtered',
          description: isString(column.description) ? column.description : undefined,
          example: isString(column.example) ? column.example : undefined,
          id: fieldId,
          type: column.type,
          width: DEFAULT_COLUMN_MIN_WIDTH,
        },
        id: timeline,
        index: result.destination != null ? result.destination.index : 0,
      })
    );
  } else {
    // create a column definition, because it doesn't exist in the browserFields:
    dispatch(
      upsertColumn({
        column: {
          columnHeaderType: 'not-filtered',
          id: fieldId,
          width: DEFAULT_COLUMN_MIN_WIDTH,
        },
        id: timeline,
        index: result.destination != null ? result.destination.index : 0,
      })
    );
  }
};
開發者ID:,項目名稱:,代碼行數:42,代碼來源:

示例6: Error

export const parseFilterQuery = (filterQuery: string): JsonObject => {
  try {
    if (filterQuery && isString(filterQuery) && !isEmpty(filterQuery)) {
      const parsedFilterQuery = JSON.parse(filterQuery);
      if (
        !parsedFilterQuery ||
        !isPlainObject(parsedFilterQuery) ||
        Array.isArray(parsedFilterQuery)
      ) {
        throw new Error('expected value to be an object');
      }
      return parsedFilterQuery;
    }
    return {};
  } catch (err) {
    throw new UserInputError(`Failed to parse query: ${err}`, {
      query: filterQuery,
      originalError: err,
    });
  }
};
開發者ID:,項目名稱:,代碼行數:21,代碼來源:

示例7: GraphQLScalarType

 *  serialize: gets invoked when serializing the result to send it back to a client.
 *
 *  parseValue: gets invoked to parse client input that was passed through variables.
 *
 *  parseLiteral: gets invoked to parse client input that was passed inline in the query.
 */

export const toNumberArrayScalar = new GraphQLScalarType({
  name: 'NumberArray',
  description: 'Represents value in detail item from the timeline who wants to more than one type',
  serialize(value): number[] | null {
    if (value == null) {
      return null;
    } else if (Array.isArray(value)) {
      return convertArrayToNumber(value) as number[];
    } else if (isBoolean(value) || isString(value) || isObject(value)) {
      return [convertToNumber(value)];
    }
    return [value];
  },
  parseValue(value) {
    return value;
  },
  parseLiteral(ast) {
    switch (ast.kind) {
      case Kind.INT:
        return ast.value;
      case Kind.FLOAT:
        return ast.value;
      case Kind.STRING:
        return parseFloat(ast.value);
開發者ID:,項目名稱:,代碼行數:31,代碼來源:


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