Skip to content

Commit

Permalink
Remove old deps
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-kinokon committed Jun 13, 2024
1 parent c310b0b commit 0d2b133
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
});
});
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
],
"author": "Spike Brehm <[email protected]>",
"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": {
Expand All @@ -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"
Expand Down
22 changes: 10 additions & 12 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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');
});
});
Expand Down Expand Up @@ -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');
});
});
Expand Down

0 comments on commit 0d2b133

Please sign in to comment.