UNPKG

granula

Version:

i18n tool for angular.js applications

53 lines (49 loc) 1.43 kB
(function() { var checkAttribute; checkAttribute = function(attribute, cbOnEmpty) { if (cbOnEmpty == null) { cbOnEmpty = function() {}; } if (attribute === void 0 || attribute.trim().length === 0) { cbOnEmpty(); return void 0; } return attribute; }; module.exports = { textToKey: function(text, options) { if (options == null) { options = { wordsLimitForKey: 10, replaceSpaces: false }; } if (!text) { return void 0; } return text.split(/\s+/).slice(0, options.wordsLimitForKey).join(options.replaceSpaces ? options.replaceSpaces : " "); }, toKey: function(attribute, text, options) { var _ref; if (options == null) { options = { textAsKey: 'nokey' }; } switch (options.textAsKey) { case true: case "always": return this.textToKey(text, options); case false: case "never": return checkAttribute(attribute, function() { throw new Error("Mandatory key attribute is not defined"); }); case "nokey": return (_ref = checkAttribute(attribute)) != null ? _ref : this.textToKey(text, options); default: throw new Error("Unknown option '" + options.textAsKey + "', possible values: 'never', 'always', 'nokey'"); } } }; }).call(this);