@angular/cdk
Version:
Angular Material Component Development Kit
44 lines (40 loc) • 1.68 kB
JavaScript
export { _ as _isNumberValue, c as coerceElement, a as coerceNumberProperty } from './element-15999318.mjs';
export { c as coerceArray } from './array-6239d2f8.mjs';
export { c as coerceCssPixelValue } from './css-pixel-value-5d0cae55.mjs';
import '@angular/core';
/** Coerces a data-bound value (typically a string) to a boolean. */
function coerceBooleanProperty(value) {
return value != null && `${value}` !== 'false';
}
/**
* Coerces a value to an array of trimmed non-empty strings.
* Any input that is not an array, `null` or `undefined` will be turned into a string
* via `toString()` and subsequently split with the given separator.
* `null` and `undefined` will result in an empty array.
* This results in the following outcomes:
* - `null` -> `[]`
* - `[null]` -> `["null"]`
* - `["a", "b ", " "]` -> `["a", "b"]`
* - `[1, [2, 3]]` -> `["1", "2,3"]`
* - `[{ a: 0 }]` -> `["[object Object]"]`
* - `{ a: 0 }` -> `["[object", "Object]"]`
*
* Useful for defining CSS classes or table columns.
* @param value the value to coerce into an array of strings
* @param separator split-separator if value isn't an array
*/
function coerceStringArray(value, separator = /\s+/) {
const result = [];
if (value != null) {
const sourceValues = Array.isArray(value) ? value : `${value}`.split(separator);
for (const sourceValue of sourceValues) {
const trimmedString = `${sourceValue}`.trim();
if (trimmedString) {
result.push(trimmedString);
}
}
}
return result;
}
export { coerceBooleanProperty, coerceStringArray };
//# sourceMappingURL=coercion.mjs.map