本文整理汇总了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";
}
}
}
示例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;
}
示例3: isDOMElementOfType
export function isDOMElementOfType(instance: any, type: string): boolean {
return (
isDOMElement(instance) &&
isString(type) &&
instance.tagName.toLowerCase() === type.toLowerCase()
);
}
示例4: isDOMElement
export function isDOMElement(instance: any): boolean {
return (
Boolean(instance) &&
isObject(instance) &&
(instance as any).nodeType === 1 &&
isString((instance as any).tagName)
);
}
示例5: parseSelector
function parseSelector(filter) {
if (isArray(filter)) {
return filter;
} else if (isString(filter)) {
return filter.trim().split(/\s+/);
} else {
return [];
}
}
示例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;
}
}
示例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;
}
示例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);
示例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
);
}
}
示例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;
};