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O,aAAc,EAAO,WAEpE,KAAK,KAAK,OAAQ,IAAI,MAAM,CACxB,IAAK,EAAS,IACd,KAAM,EAAS,KACf,KAAM,KAAK,KAAK,EAAS,KAAM,GAAG,IAAW,EAAO,MAAM,UAC1D,SAAU,IAAI,OAAO,KACtB,IAGP,KAAK,KAAK,MACd,GAqBJ","file":"/npm/gulp-merge-translations@0.1.3/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/gulp-merge-translations@0.1.3/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const PluginError = require('plugin-error');\nconst Vinyl = require('vinyl');\nconst path = require('path');\nconst through = require('through');\n\n/**\n * Merge translations files\n *\n * @param fileName {String} Base file name, it will be used to generate a name based on locale detected in each file name.\n * @param settings {Object} Configuration object with the following options:\n *  - getLocale:    {Function} Get the locale from file name, see getLocale function.\n *  - merge:        {Function} Merge the json parsed objects, defaul Object.assign.\n *  - sep:          {String}   Mark where the locale is in the file name, also used to generate file. Defaul = '_'.\n *  - jsonReplacer: {Function} See JSON.stringify for reference.\n *  - jsonSpace:    {String}   See JSON.stringify for reference.\n * @returns {*}\n */\nmodule.exports = function (fileName = 'translations', settings = {}) {\n    const PLUGIN_NAME = 'gulp-merge-translations';\n\n    const config = Object.assign({\n        getLocale: getLocale,\n        merge: Object.assign,\n        sep: '_'\n    }, settings);\n\n    const filePattern = new RegExp(`${config.sep}(.+)\\\\.json$`);\n    const mergeds = {};\n    let fileInfo = null;\n\n\tfunction validFile(file) {\n\t\tif (file.isNull()) {\n            this.queue(file);\n        } else if (file.isStream()) {\n            this.emit('error', new PluginError(PLUGIN_NAME, `${PLUGIN_NAME} + : Streaming not supported!`));\n        }\n\t}\n\t\n\tfunction setFileInfo(file) {\n\t\tif (!fileInfo) {\n            fileInfo = file;\n        }\n\t}\n\t\n\tfunction shouldIgnore(locale, contentString) {\n\t\treturn !(locale && contentString.indexOf('{') === 0);\n\t}\n\t\n    function mergeFile(file) {\n        validFile.call(this, file);\n        setFileInfo(file);\n\n        const locale = config.getLocale(path.basename(file.path));\n        const contentString = file.contents.toString('utf8').trim();\n\n        if(shouldIgnore(locale, contentString)) {\n            console.warn('WARNING: invalid file name, no locale can be found, ignoring file:', file.path);\n        } else {\n\t\t\tlet parsed = {};\n\t\t\ttry {\n\t\t\t\tparsed = JSON.parse(contentString);\n\n\t\t\t\tmergeds[locale] = mergeds[locale] || {};\n\n\t\t\t\tconfig.merge(mergeds[locale], parsed);\n\t\t\t} catch(err) {\n\t\t\t\tthis.emit('error', new PluginError(PLUGIN_NAME, `parsing ${file.path}: ${err.message}`));\n\t\t\t}\n\t\t}\n    }\n\n    /**\n     * Build the files streams and emit them\n     */\n    function endStream() {\n        Object.keys(mergeds).forEach((locale) => {\n            const merged = mergeds[locale];\n            const contents = JSON.stringify(merged, config.jsonReplacer, config.jsonSpace);\n\n            this.emit('data', new Vinyl({\n                cwd: fileInfo.cwd,\n                base: fileInfo.base,\n                path: path.join(fileInfo.base, `${fileName}${config.sep}${locale}.json`),\n                contents: new Buffer(contents)\n            }));\n        });\n\n        this.emit('end');\n    }\n\n    /**\n     * Return an the locale code parsed from file name.\n     * Ex:\n     *  const fileBaseName = 'translation_en-US.json'\n     *  console.log(getLocale(fileBaseName))\n     *\n     *  Output: 'en-US'\n     *\n     * @param fileBaseName {String} path.basename(file.path)\n     * @returns {String}\n     * @private\n     */\n    function getLocale(fileBaseName) {\n        const matches = fileBaseName.match(filePattern);\n\n        return matches && matches[1];\n    }\n\n    return through(mergeFile, endStream);\n};\n"]}