i18next-change-case-post-processor
Version:
A i18next post processor for changing the casing of text
36 lines (30 loc) • 1.08 kB
JavaScript
'use strict';
var changeCase = require('change-case');
var AVAILABLE_METHODS = ['camelCase', 'constantCase', 'dotCase', 'headerCase', 'lowerCase', 'lowerCaseFirst', 'noCase', 'paramCase', 'pascalCase', 'pathCase', 'sentenceCase', 'snakeCase', 'swapCase', 'titleCase', 'upperCase', 'upperCaseFirst'];
var changeCasePostProcessor = {
getAvailableMethods: function getAvailableMethods() {
return AVAILABLE_METHODS.slice(0);
},
changeCase: {
name: 'changeCase',
type: 'postProcessor',
process: function process(value, key) {
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
method = _ref.method;
if (!method || !AVAILABLE_METHODS.includes(method)) {
return value;
}
return changeCase[method](value);
}
}
};
AVAILABLE_METHODS.forEach(function (method) {
changeCasePostProcessor[method] = {
name: method,
type: 'postProcessor',
process: function process(value) {
return changeCase[method](value);
}
};
});
module.exports = changeCasePostProcessor;