diff --git a/index.js b/index.js index 9594c69..606588a 100644 --- a/index.js +++ b/index.js @@ -17,11 +17,8 @@ 'use strict'; -var forEach = require('array.prototype.foreach'); -var entries = require('object.entries'); var warning = require('warning'); var has = require('has'); -var trim = require('string.prototype.trim'); var warn = function warn(message) { warning(false, message); @@ -119,10 +116,10 @@ var defaultPluralRules = { function langToTypeMap(mapping) { var ret = {}; - forEach(entries(mapping), function (entry) { + Object.entries(mapping).forEach(function (entry) { var type = entry[0]; var langs = entry[1]; - forEach(langs, function (lang) { + langs.forEach(function (lang) { ret[lang] = type; }); }); @@ -242,7 +239,7 @@ function transformPhrase( options.smart_count ); - result = trim(texts[pluralTypeWithCount] || texts[0]); + result = (texts[pluralTypeWithCount] || texts[0]).trim(); } // Interpolate: Creates a `RegExp` object for each interpolation placeholder. @@ -326,7 +323,7 @@ Polyglot.prototype.locale = function (newLocale) { // // This feature is used internally to support nested phrase objects. Polyglot.prototype.extend = function (morePhrases, prefix) { - forEach(entries(morePhrases || {}), function (entry) { + Object.entries(morePhrases || {}).forEach(function (entry) { var key = entry[0]; var phrase = entry[1]; var prefixedKey = prefix ? prefix + '.' + key : key; @@ -353,7 +350,7 @@ Polyglot.prototype.unset = function (morePhrases, prefix) { if (typeof morePhrases === 'string') { delete this.phrases[morePhrases]; } else { - forEach(entries(morePhrases || {}), function (entry) { + Object.entries(morePhrases || {}).forEach(function (entry) { var key = entry[0]; var phrase = entry[1]; var prefixedKey = prefix ? prefix + '.' + key : key; diff --git a/package.json b/package.json index 7aca50a..fccc496 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,7 @@ ], "author": "Spike Brehm ", "dependencies": { - "array.prototype.foreach": "^1.0.2", "has": "^1.0.3", - "object.entries": "^1.1.5", - "string.prototype.trim": "^1.2.6", "warning": "^4.0.3" }, "devDependencies": { @@ -46,7 +43,6 @@ "mocha": "^3.5.3", "nyc": "^10.3.2", "safe-publish-latest": "^2.0.0", - "string.prototype.matchall": "^4.0.7", "uglify-js": "^2.7.3" }, "license": "BSD-2-Clause" diff --git a/test/index.js b/test/index.js index b8cae51..ee9376c 100644 --- a/test/index.js +++ b/test/index.js @@ -2,9 +2,7 @@ var Polyglot = require('../'); var expect = require('chai').expect; -var forEach = require('array.prototype.foreach'); var iterate = require('iterate-iterator'); -var matchAll = require('string.prototype.matchall'); describe('t', function () { var phrases = { @@ -139,7 +137,7 @@ describe('t', function () { var i = 0; var children = []; - iterate(matchAll(phrase, interpolationRegex), function (match) { + iterate(phrase.matchAll(interpolationRegex), function (match) { if (match.index > i) { children.push(phrase.slice(i, match.index)); } @@ -368,25 +366,25 @@ describe('locale-specific pluralization rules', function () { var polyglotLocale = new Polyglot({ phrases: phrases, locale: 'hr-HR' }); - forEach([1, 21, 31, 101], function (c) { + [1, 21, 31, 101].forEach(function (c) { expect(polyglotLocale.t('n_votes', c)).to.equal(c + ' glas'); }); - forEach([2, 3, 4, 22, 23, 24, 32, 33, 34], function (c) { + [2, 3, 4, 22, 23, 24, 32, 33, 34].forEach(function (c) { expect(polyglotLocale.t('n_votes', c)).to.equal(c + ' glasa'); }); - forEach([0, 5, 6, 11, 12, 13, 14, 15, 16, 17, 25, 26, 35, 36, 112, 113, 114], function (c) { + [0, 5, 6, 11, 12, 13, 14, 15, 16, 17, 25, 26, 35, 36, 112, 113, 114].forEach(function (c) { expect(polyglotLocale.t('n_votes', c)).to.equal(c + ' glasova'); }); var polyglotLanguageCode = new Polyglot({ phrases: phrases, locale: 'hr' }); - forEach([1, 21, 31, 101], function (c) { + [1, 21, 31, 101].forEach(function (c) { expect(polyglotLanguageCode.t('n_votes', c)).to.equal(c + ' glas'); }); - forEach([2, 3, 4, 22, 23, 24, 32, 33, 34], function (c) { + [2, 3, 4, 22, 23, 24, 32, 33, 34].forEach(function (c) { expect(polyglotLanguageCode.t('n_votes', c)).to.equal(c + ' glasa'); }); - forEach([0, 5, 6, 11, 12, 13, 14, 15, 16, 17, 25, 26, 35, 36, 112, 113, 114], function (c) { + [0, 5, 6, 11, 12, 13, 14, 15, 16, 17, 25, 26, 35, 36, 112, 113, 114].forEach(function (c) { expect(polyglotLanguageCode.t('n_votes', c)).to.equal(c + ' glasova'); }); }); @@ -512,15 +510,15 @@ describe('locale-specific pluralization rules', function () { var polyglot = new Polyglot({ phrases: phrases, locale: 'sl-SL' }); - forEach([1, 12301, 101, 1001, 201, 301], function (c) { + [1, 12301, 101, 1001, 201, 301].forEach(function (c) { expect(polyglot.t('n_votes', c)).to.equal(c + ' komentar'); }); - forEach([2, 102, 202, 302], function (c) { + [2, 102, 202, 302].forEach(function (c) { expect(polyglot.t('n_votes', c)).to.equal(c + ' komentarja'); }); - forEach([0, 11, 12, 13, 14, 52, 53], function (c) { + [0, 11, 12, 13, 14, 52, 53].forEach(function (c) { expect(polyglot.t('n_votes', c)).to.equal(c + ' komentarjev'); }); });