Sha256: 4dd75ebc60bf528ca9617910dc389309a81401ab27fddd1018632611cb1b9a15

Contents?: true

Size: 1.97 KB

Versions: 81

Compression:

Stored size: 1.97 KB

Contents

// DOM properties that should NOT have "px" added when numeric
export const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i;

const ENCODED_ENTITIES = /[&<>"]/;

export function encodeEntities(input) {
	const s = String(input);
	if (!ENCODED_ENTITIES.test(s)) {
		return s;
	}
	return s
		.replace(/&/g, '&amp;')
		.replace(/</g, '&lt;')
		.replace(/>/g, '&gt;')
		.replace(/"/g, '&quot;');
}

export let indent = (s, char) =>
	String(s).replace(/(\n+)/g, '$1' + (char || '\t'));

export let isLargeString = (s, length, ignoreLines) =>
	String(s).length > (length || 40) ||
	(!ignoreLines && String(s).indexOf('\n') !== -1) ||
	String(s).indexOf('<') !== -1;

const JS_TO_CSS = {};

// Convert an Object style to a CSSText string
export function styleObjToCss(s) {
	let str = '';
	for (let prop in s) {
		let val = s[prop];
		if (val != null && val !== '') {
			if (str) str += ' ';
			// str += jsToCss(prop);
			str +=
				prop[0] == '-'
					? prop
					: JS_TO_CSS[prop] ||
					  (JS_TO_CSS[prop] = prop.replace(/([A-Z])/g, '-$1').toLowerCase());
			str += ': ';
			str += val;
			if (typeof val === 'number' && IS_NON_DIMENSIONAL.test(prop) === false) {
				str += 'px';
			}
			str += ';';
		}
	}
	return str || undefined;
}

/**
 * Copy all properties from `props` onto `obj`.
 * @param {object} obj Object onto which properties should be copied.
 * @param {object} props Object from which to copy properties.
 * @returns {object}
 * @private
 */
export function assign(obj, props) {
	for (let i in props) obj[i] = props[i];
	return obj;
}

/**
 * Get flattened children from the children prop
 * @param {Array} accumulator
 * @param {any} children A `props.children` opaque object.
 * @returns {Array} accumulator
 * @private
 */
export function getChildren(accumulator, children) {
	if (Array.isArray(children)) {
		children.reduce(getChildren, accumulator);
	} else if (children != null && children !== false) {
		accumulator.push(children);
	}
	return accumulator;
}

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
isomorfeus-preact-10.9.0 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.8.2 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.8.1 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.8.0 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.7.3 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.7.2 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.7.1 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.7.0 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.62 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.61 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.60 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.59 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.58 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.57 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.56 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.55 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.54 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.53 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.52 node_modules/preact-render-to-string/src/util.js
isomorfeus-preact-10.6.51 node_modules/preact-render-to-string/src/util.js