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


TypeScript inferno-shared.isString函数代码示例

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


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

示例1: patchStyle

// We are assuming here that we come from patchProp routine
// -nextAttrValue cannot be null or undefined
function patchStyle(lastAttrValue, nextAttrValue, dom) {
  const domStyle = dom.style;
  let style;
  let value;

  if (isString(nextAttrValue)) {
    domStyle.cssText = nextAttrValue;
    return;
  }

  if (!isNullOrUndef(lastAttrValue) && !isString(lastAttrValue)) {
    for (style in nextAttrValue) {
      // do not add a hasOwnProperty check here, it affects performance
      value = nextAttrValue[style];
      if (value !== lastAttrValue[style]) {
        domStyle[style] =
          !isNumber(value) || isUnitlessNumber.has(style)
            ? value
            : value + "px";
      }
    }

    for (style in lastAttrValue) {
      if (isNullOrUndef(nextAttrValue[style])) {
        domStyle[style] = "";
      }
    }
  } else {
    for (style in nextAttrValue) {
      value = nextAttrValue[style];
      domStyle[style] =
        !isNumber(value) || isUnitlessNumber.has(style) ? value : value + "px";
    }
  }
}
开发者ID:russelgal,项目名称:inferno,代码行数:37,代码来源:patching.ts

示例2: renderAttributes

export function renderAttributes(props): string[] {
  const outputAttrs: string[] = [];
  const propsKeys = (props && Object.keys(props)) || [];

  for (let i = 0, len = propsKeys.length; i < len; i++) {
    const prop = propsKeys[i];

    if (
      prop !== "children" &&
      prop !== "dangerouslySetInnerHTML" &&
      prop !== "style"
    ) {
      const value = props[prop];

      if (isString(value)) {
        outputAttrs.push(prop + '="' + escapeText(value) + '"');
      } else if (isNumber(value)) {
        outputAttrs.push(prop + '="' + value + '"');
      } else if (isTrue(value)) {
        outputAttrs.push(prop);
      }
    }
  }

  return outputAttrs;
}
开发者ID:russelgal,项目名称:inferno,代码行数:26,代码来源:prop-renderers.ts

示例3: isDOMElementOfType

export function isDOMElementOfType(instance: any, type: string): boolean {
  return (
    isDOMElement(instance) &&
    isString(type) &&
    instance.tagName.toLowerCase() === type.toLowerCase()
  );
}
开发者ID:russelgal,项目名称:inferno,代码行数:7,代码来源:index.ts

示例4: isDOMElement

export function isDOMElement(instance: any): boolean {
  return (
    Boolean(instance) &&
    isObject(instance) &&
    (instance as any).nodeType === 1 &&
    isString((instance as any).tagName)
  );
}
开发者ID:russelgal,项目名称:inferno,代码行数:8,代码来源:index.ts

示例5: parseSelector

function parseSelector(filter) {
  if (isArray(filter)) {
    return filter;
  } else if (isString(filter)) {
    return filter.trim().split(/\s+/);
  } else {
    return [];
  }
}
开发者ID:russelgal,项目名称:inferno,代码行数:9,代码来源:index.ts

示例6: renderStylesToString

export function renderStylesToString(styles: string | object): string {
  if (isString(styles)) {
    return styles;
  } else {
    let renderedString = "";
    for (const styleName in styles) {
      const value = styles[styleName];

      if (isString(value)) {
        renderedString += `${getCssPropertyName(styleName)}${value};`;
      } else if (isNumber(value)) {
        renderedString += `${getCssPropertyName(
          styleName
        )}${value}${internal_isUnitlessNumber.has(styleName) ? "" : "px"};`;
      }
    }
    return renderedString;
  }
}
开发者ID:russelgal,项目名称:inferno,代码行数:19,代码来源:prop-renderers.ts

示例7: vNodeToSnapshot

export function vNodeToSnapshot(node: VNode) {
  let object;
  const children: any[] = [];
  if (isDOMVNode(node)) {
    const props = { className: node.className || undefined, ...node.props };

    // Remove undefined props
    Object.keys(props).forEach(propKey => {
      if (props[propKey] === undefined) {
        delete props[propKey];
      }
    });

    // Create the actual object that Jest will interpret as the snapshot for this VNode
    object = createSnapshotObject({
      props,
      type: getTagNameOfVNode(node)
    });
  }

  if (isArray(node.children)) {
    node.children.forEach(child => {
      const asJSON = vNodeToSnapshot(child as VNode);
      if (asJSON) {
        children.push(asJSON);
      }
    });
  } else if (isString(node.children)) {
    children.push(node.children);
  } else if (isObject(node.children) && !isNull(node.children)) {
    const asJSON = vNodeToSnapshot(node.children);
    if (asJSON) {
      children.push(asJSON);
    }
  }

  if (object) {
    object.children = children.length ? children : null;
    return object;
  }

  if (children.length > 1) {
    return children;
  } else if (children.length === 1) {
    return children[0];
  }

  return object;
}
开发者ID:russelgal,项目名称:inferno,代码行数:49,代码来源:jest.ts

示例8: findAllInRenderedTree

 return findAllInRenderedTree(renderedTree, instance => {
   if (isDOMVNode(instance)) {
     let domClassName = (instance.dom as Element).className;
     if (
       !isString(domClassName) &&
       !isNullOrUndef(instance.dom) &&
       isFunction(instance.dom.getAttribute)
     ) {
       // SVG || null, probably
       domClassName = (instance.dom as Element).getAttribute("class") || "";
     }
     const domClassList = parseSelector(domClassName);
     return parseSelector(classNames).every(className => {
       return domClassList.indexOf(className) !== -1;
     });
   }
   return false;
 }).map(instance => instance.dom);
开发者ID:russelgal,项目名称:inferno,代码行数:18,代码来源:index.ts

示例9: hyperscript

/**
 * Creates virtual node
 * @param {string|VNode|Function} _tag Name for virtual node
 * @param {object=} _props Additional properties for virtual node
 * @param {string|number|VNode|Array<string|number|VNode>|null=} _children Optional children for virtual node
 * @returns {VNode} returns new virtual node
 */
export default function hyperscript(
  _tag: string | VNode | Function,
  _props?: any,
  _children?: InfernoChildren
): VNode {
  // If a child array or text node are passed as the second argument, shift them
  if (!_children && isChildren(_props)) {
    _children = _props;
    _props = {};
  }
  const isElement = isString(_tag);
  const { tag, props, key, ref, children, className } = extractProps(
    _props,
    isElement,
    _tag as VNode
  );

  if (isElement) {
    return createVNode(
      getFlagsForElementVnode(tag),
      tag,
      className,
      _children || children,
      props,
      key,
      ref
    );
  } else {
    if (children || _children) {
      (props as any).children = children || _children;
    }
    return createVNode(
      VNodeFlags.ComponentUnknown,
      tag,
      className,
      null,
      props,
      key,
      ref
    );
  }
}
开发者ID:russelgal,项目名称:inferno,代码行数:49,代码来源:index.ts

示例10: function

  return function(name, _props, ...children) {
    const props = _props || {};
    const ref = props.ref;

    if (typeof ref === "string" && !isNull(currentComponent)) {
      currentComponent.refs = currentComponent.refs || {};
      props.ref = function(val) {
        this.refs[ref] = val;
      }.bind(currentComponent);
    }
    if (typeof name === "string") {
      normalizeProps(name, props);
    }

    // React supports iterable children, in addition to Array-like
    if (hasSymbolSupport) {
      for (let i = 0, len = children.length; i < len; i++) {
        const child = children[i];
        if (
          child &&
          !isArray(child) &&
          !isString(child) &&
          isFunction(child[Symbol.iterator])
        ) {
          children[i] = iterableToArray(child[Symbol.iterator]());
        }
      }
    }
    const vnode = originalFunction(name, props, ...children);

    if (vnode.className) {
      vnode.props = vnode.props || {};
      vnode.props.className = vnode.className;
    }

    return vnode;
  };
开发者ID:russelgal,项目名称:inferno,代码行数:37,代码来源:index.ts


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