UNPKG

@ezs/basics

Version:
61 lines (59 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _lodash = require("lodash"); var _inflection = require("inflection"); const transformer = transformations => str => str && typeof str === 'string' ? (0, _inflection.transform)(str, transformations) : str; const TXTInflection = (data, feed, ctx) => { if (ctx.isLast()) { return feed.close(); } const transformations = [].concat(ctx.getParam('transform', [])).filter(Boolean); const path = ctx.getParam('path', 'value'); const value = (0, _lodash.get)(data, path, ''); const process = transformer(transformations); const result = Array.isArray(value) ? value.map(item => process(item)) : process(value); feed.write({ ...data, [path]: result }); return feed.end(); }; /** * Take a `String` and inflect it with or more transformers from this list * pluralize, singularize, camelize, underscore, humanize, capitalize, * dasherize, titleize, demodulize, tableize, classify, foreign_key, ordinalize * * Input: * * ```json * { "id": 1, "value": "all job" } * ``` * Script: * ```ini * [TXTInflection] * transform = pluralize * transform = capitalize * transform = dasherize * ``` * * Output: * * ```json * { "id": 1, "value": "All-jobs" } * ``` * * @name TXTInflection * @param {String} [path="value"] path of the field to segment * @param {String} [transform] name of a transformer * @returns {String[]} * @deprecated * see https://inist-cnrs.github.io/ezs/#/plugin-strings?id=inflection * see https://www.npmjs.com/package/inflection */ var _default = { TXTInflection }; exports.default = _default;