From 52527ba0509b7dbb203c22a09d7043c8f89df4ac Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 11 Jul 2024 14:36:58 -0700 Subject: [PATCH 1/7] [Deps] update `aud`, `chai`, `docco`, `eslint-plugin-import`, `string.prototype.matchall` --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7aca50a..f7bf366 100644 --- a/package.json +++ b/package.json @@ -35,18 +35,18 @@ "warning": "^4.0.3" }, "devDependencies": { - "aud": "^2.0.0", + "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" From afe415960b9023ec6d908b10edaf0089873ff669 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 11 Jul 2024 14:37:43 -0700 Subject: [PATCH 2/7] [Refactor] use `hasown` instead of `has` --- index.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9594c69..6d86a2a 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ var forEach = require('array.prototype.foreach'); var entries = require('object.entries'); var warning = require('warning'); -var has = require('has'); +var has = require('hasown'); var trim = require('string.prototype.trim'); var warn = function warn(message) { diff --git a/package.json b/package.json index f7bf366..2a48f17 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "author": "Spike Brehm ", "dependencies": { "array.prototype.foreach": "^1.0.2", - "has": "^1.0.3", + "hasown": "^2.0.2", "object.entries": "^1.1.5", "string.prototype.trim": "^1.2.6", "warning": "^4.0.3" From 777bf93c44982d557a40eebdf6ac171269259d78 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 11 Jul 2024 14:38:10 -0700 Subject: [PATCH 3/7] [Deps] update `array.prototype.foreach`, `object.entries`, `string.prototype.trim` --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2a48f17..ea99fbf 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,10 @@ ], "author": "Spike Brehm ", "dependencies": { - "array.prototype.foreach": "^1.0.2", + "array.prototype.foreach": "^1.0.7", "hasown": "^2.0.2", - "object.entries": "^1.1.5", - "string.prototype.trim": "^1.2.6", + "object.entries": "^1.1.8", + "string.prototype.trim": "^1.2.9", "warning": "^4.0.3" }, "devDependencies": { From 21c64d451afe144c3309144aef1a4e8346ab74d8 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 11 Jul 2024 15:08:59 -0700 Subject: [PATCH 4/7] [meta] add missing `engines.node` --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ea99fbf..132c3bf 100644 --- a/package.json +++ b/package.json @@ -49,5 +49,8 @@ "string.prototype.matchall": "^4.0.11", "uglify-js": "^2.7.3" }, - "license": "BSD-2-Clause" + "license": "BSD-2-Clause", + "engines": { + "node": ">= 0.4" + } } From 831cc6536a358111bf715f4be0d766d369f1dd21 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 11 Jul 2024 15:06:24 -0700 Subject: [PATCH 5/7] [eslint] disable yoda rule entirely --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, } } From 8e58f2e81a4a8db9a6981b2aaea691113d99ed9a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 11 Jul 2024 15:02:19 -0700 Subject: [PATCH 6/7] [Refactor] remove `string.prototype.trim` --- index.js | 3 +-- package.json | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index 6d86a2a..3fc7524 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,6 @@ var forEach = require('array.prototype.foreach'); var entries = require('object.entries'); var warning = require('warning'); var has = require('hasown'); -var trim = require('string.prototype.trim'); var warn = function warn(message) { warning(false, message); @@ -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. diff --git a/package.json b/package.json index 132c3bf..695a8d1 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "array.prototype.foreach": "^1.0.7", "hasown": "^2.0.2", "object.entries": "^1.1.8", - "string.prototype.trim": "^1.2.9", "warning": "^4.0.3" }, "devDependencies": { From 78022fee8ee14ded7788a5eb02cf2c0b22864972 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 11 Jul 2024 15:06:38 -0700 Subject: [PATCH 7/7] [Refactor] remove `array.prototype.foreach` --- index.js | 34 ++++++++++++++++++---------------- package.json | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 3fc7524..5f4d0de 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,6 @@ 'use strict'; -var forEach = require('array.prototype.foreach'); var entries = require('object.entries'); var warning = require('warning'); var has = require('hasown'); @@ -118,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; } @@ -325,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) @@ -352,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 695a8d1..2d98feb 100644 --- a/package.json +++ b/package.json @@ -28,12 +28,12 @@ ], "author": "Spike Brehm ", "dependencies": { - "array.prototype.foreach": "^1.0.7", "hasown": "^2.0.2", "object.entries": "^1.1.8", "warning": "^4.0.3" }, "devDependencies": { + "array.prototype.foreach": "^1.0.7", "aud": "^2.0.4", "chai": "^3.5.0", "docco": "^0.7.0",