
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
@onigoetz/make-plural
Advanced tools
This package is a fork of [`make-plural`](https://www.npmjs.com/package/make-plural) version 4.
This package is a fork of make-plural
version 4.
It provided a compiler for CLDR plurals, but it also contained a lot of methods to test them. I stripped the test methods and kept the conversion code to make it smaller.
import makePlural from "@onigoetz/make-plural";
// Original CLDR data
const pluralRules = {
"plurals-type-cardinal": {
en: {
"pluralRule-count-one": "i = 1 and v = 0 @integer 1",
"pluralRule-count-other":
" @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
}
},
"plurals-type-ordinal": {
en: {
"pluralRule-count-one":
"n % 10 = 1 and n % 100 != 11 @integer 1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, …",
"pluralRule-count-two":
"n % 10 = 2 and n % 100 != 12 @integer 2, 22, 32, 42, 52, 62, 72, 82, 102, 1002, …",
"pluralRule-count-few":
"n % 10 = 3 and n % 100 != 13 @integer 3, 23, 33, 43, 53, 63, 73, 83, 103, 1003, …",
"pluralRule-count-other":
" @integer 0, 4~18, 100, 1000, 10000, 100000, 1000000, …"
}
}
};
const pluralGenerator = makePlural(pluralRules["plurals-type-ordinal"]["en"]);
console.log(pluralGenerator(3)) // => few
The original CLDR data is quite verbose and if you can preprocess it, a lot of data can be removed.
You can remove anything after @decimal
or @integer
and the other
rule, you can go from :
{
"plurals-type-cardinal": {
"en": {
"pluralRule-count-one": "i = 1 and v = 0 @integer 1",
"pluralRule-count-other":
" @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
}
},
"plurals-type-ordinal": {
"en": {
"pluralRule-count-one":
"n % 10 = 1 and n % 100 != 11 @integer 1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, …",
"pluralRule-count-two":
"n % 10 = 2 and n % 100 != 12 @integer 2, 22, 32, 42, 52, 62, 72, 82, 102, 1002, …",
"pluralRule-count-few":
"n % 10 = 3 and n % 100 != 13 @integer 3, 23, 33, 43, 53, 63, 73, 83, 103, 1003, …",
"pluralRule-count-other":
" @integer 0, 4~18, 100, 1000, 10000, 100000, 1000000, …"
}
}
}
to :
{
"plurals-type-cardinal": {
"en": {
"pluralRule-count-one": "i = 1 and v = 0"
}
},
"plurals-type-ordinal": {
"en": {
"pluralRule-count-one": "n % 10 = 1 and n % 100 != 11",
"pluralRule-count-two": "n % 10 = 2 and n % 100 != 12",
"pluralRule-count-few": "n % 10 = 3 and n % 100 != 13"
}
}
}
If you need to create many plural generators, parsing the CLDR data many times isn't efficient. You can create a small factory function like this:
const pluralRules = {}; // CLDR data
const pluralMemory = {};
function pluralGenerator(locale, type) {
const key = `${locale}-${type}`;
if (!pluralMemory.hasOwnProperty(key)) {
pluralMemory[key] = makePlural(
pluralRules[`plurals-type-${type}`][locale]
);
}
return pluralMemory[key];
}
FAQs
This package is a fork of [`make-plural`](https://www.npmjs.com/package/make-plural) version 4.
We found that @onigoetz/make-plural demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.