/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * 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 */ export 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; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RyaW5nLWFycmF5LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9jb2VyY2lvbi9zdHJpbmctYXJyYXkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUg7Ozs7Ozs7Ozs7Ozs7Ozs7R0FnQkc7QUFDSCxNQUFNLFVBQVUsaUJBQWlCLENBQUMsS0FBVSxFQUFFLFlBQTZCLEtBQUs7SUFDOUUsTUFBTSxNQUFNLEdBQUcsRUFBRSxDQUFDO0lBRWxCLElBQUksS0FBSyxJQUFJLElBQUksRUFBRTtRQUNqQixNQUFNLFlBQVksR0FBRyxLQUFLLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxDQUFDLEdBQUcsS0FBSyxFQUFFLENBQUMsS0FBSyxDQU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