diff --git a/.eslintrc b/.eslintrc index bd44a09..19e0857 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,6 +13,6 @@ "one-var-declaration-per-line": 0, "no-use-before-define": 1, "vars-on-top": 0, - "yoda": 1, + "yoda": 0, } } diff --git a/index.js b/index.js index 9594c69..5f4d0de 100644 --- a/index.js +++ b/index.js @@ -17,11 +17,9 @@ '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 has = require('hasown'); var warn = function warn(message) { warning(false, message); @@ -119,13 +117,14 @@ var defaultPluralRules = { function langToTypeMap(mapping) { var ret = {}; - forEach(entries(mapping), function (entry) { - var type = entry[0]; - var langs = entry[1]; - forEach(langs, function (lang) { - ret[lang] = type; - }); - }); + var mappingEntries = entries(mapping); + for (var i = 0; i < mappingEntries.length; i += 1) { + var type = mappingEntries[i][0]; + var langs = mappingEntries[i][1]; + for (var j = 0; j < langs.length; j += 1) { + ret[langs[j]] = type; + } + } return ret; } @@ -242,7 +241,7 @@ function transformPhrase( options.smart_count ); - result = trim(texts[pluralTypeWithCount] || texts[0]); + result = defaultReplace.call(texts[pluralTypeWithCount] || texts[0], /^[^\S]*|[^\S]*$/g, ''); } // Interpolate: Creates a `RegExp` object for each interpolation placeholder. @@ -326,16 +325,17 @@ 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) { - var key = entry[0]; - var phrase = entry[1]; + var phraseEntries = entries(morePhrases || {}); + for (var i = 0; i < phraseEntries.length; i += 1) { + var key = phraseEntries[i][0]; + var phrase = phraseEntries[i][1]; var prefixedKey = prefix ? prefix + '.' + key : key; if (typeof phrase === 'object') { this.extend(phrase, prefixedKey); } else { this.phrases[prefixedKey] = phrase; } - }, this); + } }; // ### polyglot.unset(phrases) @@ -353,16 +353,17 @@ Polyglot.prototype.unset = function (morePhrases, prefix) { if (typeof morePhrases === 'string') { delete this.phrases[morePhrases]; } else { - forEach(entries(morePhrases || {}), function (entry) { - var key = entry[0]; - var phrase = entry[1]; + var phraseEntries = entries(morePhrases || {}); + for (var i = 0; i < phraseEntries.length; i += 1) { + var key = phraseEntries[i][0]; + var phrase = phraseEntries[i][1]; var prefixedKey = prefix ? prefix + '.' + key : key; if (typeof phrase === 'object') { this.unset(phrase, prefixedKey); } else { delete this.phrases[prefixedKey]; } - }, this); + } } }; diff --git a/package.json b/package.json index 7aca50a..2d98feb 100644 --- a/package.json +++ b/package.json @@ -28,26 +28,28 @@ ], "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", + "hasown": "^2.0.2", + "object.entries": "^1.1.8", "warning": "^4.0.3" }, "devDependencies": { - "aud": "^2.0.0", + "array.prototype.foreach": "^1.0.7", + "aud": "^2.0.4", "chai": "^3.5.0", "docco": "^0.7.0", "eslint": "^8.18.0", "eslint-config-airbnb-base": "^15.0.0", - "eslint-plugin-import": "^2.23.4", + "eslint-plugin-import": "^2.29.1", "in-publish": "^2.0.1", "iterate-iterator": "^1.0.2", "mocha": "^3.5.3", "nyc": "^10.3.2", "safe-publish-latest": "^2.0.0", - "string.prototype.matchall": "^4.0.7", + "string.prototype.matchall": "^4.0.11", "uglify-js": "^2.7.3" }, - "license": "BSD-2-Clause" + "license": "BSD-2-Clause", + "engines": { + "node": ">= 0.4" + } }