UNPKG

voca

Version:

The ultimate JavaScript string library

32 lines (25 loc) 846 B
import { i as isNil } from './is_nil.js'; import isString from '../is_string.js'; /** * Get the string representation of the `value`. * Converts the `value` to string. * If `value` is `null` or `undefined`, return `defaultValue`. * * @ignore * @function toString * @param {*} value The value to convert. * @param {*} [defaultValue=''] The default value to return. * @return {string|null} Returns the string representation of `value`. Returns `defaultValue` if `value` is * `null` or `undefined`. */ function coerceToString(value) { var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; if (isNil(value)) { return defaultValue; } if (isString(value)) { return value; } return String(value); } export { coerceToString as c };