get_zero
v1.1.0
Published
Any zero you want.
Maintainers
Readme
What is it?
Package for getting zero in any form you want.
Installation
Run npm i get_zero or yarn add get_zero etc.
Use
import getZero from "get_zero";
Without parameter:
- Default: getZero() returns 0 (number);
With parameter:
- Option 1: getZero("number") returns 0 (number);
- Option 2: getZero("string") returns "0" (string);
- Option 3: getZero("object") returns {0: 0} (object);
- Option 4: getZero("array_number") returns [0] (number[]);
- Option 5: getZero("array_string") returns ["0"] (string[]);
- Option 6: getZero("word") returns "zero" (string), automatically localized to the user's system locale;
Localizing Option 6 ("word")
By default, getZero("word") detects the current system/browser locale and returns the word for zero in that language, falling back to English ("zero") if the locale isn't recognized:
- getZero("word") →
"zero"on an English system,"cero"on a Spanish system,"zéro"on a French system, etc.
You can also force a specific locale instead of relying on auto-detection, by passing it as a second argument:
- getZero("word", "es") returns "cero";
- getZero("word", "fr") returns "zéro";
- getZero("word", "de") returns "null";
Region-specific tags also work (only the base language is used) — e.g. getZero("word", "es-MX") returns "cero", getZero("word", "zh-CN") returns "零".
⚠️ The
localeargument only exists on the"word"option. Passing it with any other option — e.g.getZero("number", "es")— is a TypeScript type error, not just ignored at runtime. In plain JavaScript, without type-checking, it's simply ignored for non-"word"options.
Supported locale codes
Anything not in this list falls back to English:
en, es, fr, de, it, pt, nl, sv, da, no, nb, nn, fi, is, pl, cs, sk, ro, hu, bg, hr, sr, sl, lt, lv, et, uk, ru, el, tr, he, ar, fa, ur, hi, bn, ta, te, mr, gu, pa, th, vi, id, ms, zh, ja, ko, sw, af, ca, gl, eu
In an editor like VS Code, typing getZero("word", " will pop up these codes as autocomplete suggestions — but you're not limited to them. The argument still accepts any other locale string (e.g. a region variant like "pt-BR", or a language not in the list); it just won't be offered as a suggestion.
Advanced: getLocalizedZeroWord
The localization logic behind Option 6 is also exported directly, in case you want the word without going through getZero:
import { getLocalizedZeroWord } from "get_zero";
- getLocalizedZeroWord() returns the word for zero in the auto-detected system locale;
- getLocalizedZeroWord("es") returns "cero";
