UNPKG

stringiful

Version:

Easy to use stringify function with built-in configurable formatters

26 lines 1.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getStringFormatter = void 0; const lodash_1 = __importDefault(require("lodash")); const config_1 = __importDefault(require("../../config")); const getStringFormatter = (formatterConfig) => { var _a; const { formattersDefaultParams: { string: { maxLength }, }, } = config_1.default; const stringFormatter = { matches: (obj) => { return lodash_1.default.isString(obj); }, }; const defaultFormatFunction = (str) => { var _a, _b; const selectedMaxLength = (_b = (_a = formatterConfig.params) === null || _a === void 0 ? void 0 : _a.maxLength) !== null && _b !== void 0 ? _b : maxLength; return str.length > selectedMaxLength ? `${str.slice(0, selectedMaxLength)}...` : str; }; stringFormatter.format = (_a = formatterConfig.format) !== null && _a !== void 0 ? _a : defaultFormatFunction; return stringFormatter; }; exports.getStringFormatter = getStringFormatter; //# sourceMappingURL=string.js.map