nhb-toolbox
Version:
A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.
441 lines (440 loc) • 9.4 kB
JavaScript
export const irregularRules = /* @__PURE__ */ Object.freeze([
['I', 'we'],
['me', 'us'],
['he', 'they'],
['she', 'they'],
['them', 'them'],
['myself', 'ourselves'],
['yourself', 'yourselves'],
['itself', 'themselves'],
['herself', 'themselves'],
['himself', 'themselves'],
['themself', 'themselves'],
['this', 'these'],
['that', 'those'],
['my', 'our'],
['its', 'their'],
['his', 'their'],
['her', 'their'],
['is', 'are'],
['was', 'were'],
['has', 'have'],
['analysis', 'analyses'],
['anathema', 'anathemata'],
['appendix', 'appendices'],
['automaton', 'automata'],
['basis', 'bases'],
['calf', 'calves'],
['carve', 'carves'],
['child', 'children'],
['codex', 'codices'],
['criterion', 'criteria'],
['crisis', 'crises'],
['datum', 'data'],
['diagnosis', 'diagnoses'],
['die', 'dice'],
['dogma', 'dogmata'],
['echo', 'echoes'],
['elf', 'elves'],
['foot', 'feet'],
['genus', 'genera'],
['goose', 'geese'],
['groove', 'grooves'],
['half', 'halves'],
['hedron', 'hedra'],
['hero', 'heroes'],
['hoof', 'hooves'],
['human', 'humans'],
['honey', 'honeys'],
['index', 'indices'],
['leaf', 'leaves'],
['lemma', 'lemmata'],
['loaf', 'loaves'],
['looey', 'looies'],
['man', 'men'],
['mango', 'mangoes'],
['matrix', 'matrices'],
['medium', 'media'],
['mouse', 'mice'],
['neurosis', 'neuroses'],
['noumenon', 'noumena'],
['organon', 'organa'],
['ox', 'oxen'],
['passerby', 'passersby'],
['phenomenon', 'phenomena'],
['pickaxe', 'pickaxes'],
['potato', 'potatoes'],
['prolegomenon', 'prolegomena'],
['proof', 'proofs'],
['quiz', 'quizzes'],
['schema', 'schemata'],
['self', 'selves'],
['shelf', 'shelves'],
['stigma', 'stigmata'],
['stoma', 'stomata'],
['thief', 'thieves'],
['tooth', 'teeth'],
['tomato', 'tomatoes'],
['torpedo', 'torpedoes'],
['tornado', 'tornadoes'],
['valve', 'valves'],
['vertex', 'vertices'],
['virus', 'viruses'],
['viscus', 'viscera'],
['volcano', 'volcanoes'],
['woman', 'women'],
['wolf', 'wolves'],
['yes', 'yeses'],
]);
export const pluralRules = /* @__PURE__ */ Object.freeze([
[/s?$/i, 's'],
[/(pe)(rson|ople)$/i, '$1ople'],
[/(child)(?:ren)?$/i, '$1ren'],
[/(alumn|alg|vertebr)(?:a|ae)$/i, '$1ae'],
[
/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,
'$1a',
],
[
/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)um$/i,
'$1a',
],
[/(octop|vir)us$/i, '$1i'],
[/(cris|ax|test)is$/i, '$1es'],
[/(alias|status)$/i, '$1es'],
[/(shoe)$/i, '$1s'],
[/(bus)$/i, '$1es'],
[/(o)es$/i, '$1es'],
[/(x|ch|ss|sh|zz)$/i, '$1es'],
[/(her|at|gr)o$/i, '$1oes'],
[/sis$/i, 'ses'],
[/^(chief|chef|belief|roof|cliff|reef)$/i, '$1s'],
[/(seraph|cherub)$/i, '$1im'],
[/(kni|wi|li)fe$/i, '$1ves'],
[/(ar|l|ea|eo|oa|hoo)f$/i, '$1ves'],
[/([^aeiouy]|qu)y$/i, '$1ies'],
[/(tive)$/i, '$1s'],
[/(hive)$/i, '$1s'],
[/(quiz)$/i, '$1zes'],
[/m[ae]n$/i, 'men'],
[/eaux$/i, '$0'],
[
/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
'$1i',
],
]);
export const singularRules = /* @__PURE__ */ Object.freeze([
[/s$/i, ''],
[/(\P{ASCII})$/u, '$1'],
[/(pe)(rson|ople)$/i, '$1rson'],
[/(child)ren$/i, '$1'],
[/(eau)x?$/i, '$1'],
[/men$/i, 'man'],
[/(matr|append)ices$/i, '$1ix'],
[/(cod|mur|sil|vert|ind)ices$/i, '$1ex'],
[/(alumn|alg|vertebr)ae$/i, '$1a'],
[
/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,
'$1on',
],
[
/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,
'$1um',
],
[/(test)(?:is|es)$/i, '$1is'],
[/(movie|twelve|abuse|e[mn]u)s$/i, '$1'],
[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, '$1sis'],
[
/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,
'$1',
],
[/^(chief|chef|belief|roof|cliff|reef)s$/i, '$1'],
[/(seraph|cherub)im$/i, '$1'],
[/\b((?:tit)?m|l)ice$/i, '$1ouse'],
[/\b(mon|smil)ies$/i, '$1ey'],
[
/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i,
'$1ie',
],
[/ies$/i, 'y'],
[/(kni|wi|li)ves$/i, '$1fe'],
[/(ar|l|ea|eo|oa|hoo)ves$/i, '$1f'],
[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, '$1f'],
[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, '$1fe'],
[/(ss)$/i, '$1'],
[/(quiz)zes$/i, '$1'],
[/(vert|ind)ices$/i, '$1ex'],
[/^(ox)en$/i, '$1'],
[/(alias|status)es$/i, '$1'],
[/(octop|vir)i$/i, '$1us'],
[/(cris|ax|test)es$/i, '$1is'],
[/(shoe)s$/i, '$1'],
[/(her|at|gr)oes$/i, '$1o'],
[/oes$/i, 'o'],
[/(bus)es$/i, '$1'],
[/ices$/i, 'ex'],
[/(hive)s$/i, '$1'],
[/(tive)s$/i, '$1'],
[/([^f])ves$/i, '$1fe'],
[/([lr])ves$/i, '$1f'],
[/(^analy)ses$/i, '$1sis'],
[/([ti])a$/i, '$1um'],
[/(n)ews$/i, '$1ews'],
[
/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
'$1us',
],
]);
export const uncountables = /* @__PURE__ */ Object.freeze(new Set([
'aircraft',
'alcohol',
'ammo',
'analytics',
'anime',
'athletics',
'audio',
'bison',
'blood',
'butter',
'cash',
'chess',
'clothing',
'commerce',
'corps',
'debris',
'diabetes',
'energy',
'equipment',
'furniture',
'hardware',
'headquarters',
'health',
'homework',
'housework',
'information',
'insurance',
'jewelry',
'jewellery',
'knowledge',
'livestock',
'luck',
'machinery',
'metadata',
'money',
'music',
'news',
'poetry',
'pollution',
'research',
'rice',
'series',
'software',
'species',
'staff',
'traffic',
'transportation',
'weather',
'wildlife',
'you',
'adulthood',
'advertising',
'anger',
'applause',
'arithmetic',
'bacon',
'beef',
'biology',
'botany',
'carbon',
'chaos',
'cheese',
'childhood',
'coffee',
'compassion',
'cotton',
'dancing',
'delight',
'dignity',
'dirt',
'distribution',
'dust',
'economics',
'education',
'electricity',
'engineering',
'envy',
'ethics',
'evidence',
'evolution',
'failure',
'faith',
'fame',
'fiction',
'flour',
'flu',
'freedom',
'fuel',
'fun',
'garbage',
'garlic',
'genetics',
'golf',
'gossip',
'grammar',
'gratitude',
'grief',
'guilt',
'gymnastics',
'happiness',
'harm',
'hate',
'hatred',
'height',
'help',
'honesty',
'hospitality',
'humor',
'humour',
'hunger',
'importance',
'inflation',
'injustice',
'innocence',
'intelligence',
'irony',
'jealousy',
'joy',
'judo',
'justice',
'karate',
'kindness',
'labour',
'lack',
'laughter',
'lava',
'leather',
'leisure',
'lightning',
'linguistics',
'literature',
'litter',
'logic',
'loneliness',
'love',
'luggage',
'magic',
'management',
'mankind',
'marble',
'mathematics',
'mayonnaise',
'measles',
'meat',
'methane',
'mud',
'nature',
'nitrogen',
'nonsense',
'nurture',
'nutrition',
'obedience',
'obesity',
'passion',
'patience',
'permission',
'physics',
'poverty',
'pride',
'production',
'progress',
'pronunciation',
'psychology',
'publicity',
'punctuation',
'quality',
'quantity',
'quartz',
'racism',
'rain',
'recreation',
'relaxation',
'reliability',
'research',
'respect',
'revenge',
'rubbish',
'rum',
'safety',
'salt',
'sand',
'satire',
'scenery',
'shame',
'shopping',
'silence',
'sleep',
'smoke',
'smoking',
'snow',
'soap',
'soil',
'sorrow',
'speed',
'spelling',
'steam',
'strength',
'stuff',
'stupidity',
'success',
'sugar',
'sunshine',
'symmetry',
'tea',
'tennis',
'thirst',
'thunder',
'timber',
'toast',
'tolerance',
'trade',
'trust',
'understanding',
'underwear',
'unemployment',
'unity',
'usage',
'validity',
'veal',
'vegetation',
'vegetarianism',
'vengeance',
'violence',
'vision',
'vitality',
'warmth',
'wealth',
'weight',
'welfare',
'whiskey',
'width',
'wisdom',
'wool',
'yeast',
'yoga',
'youth',
'zinc',
'zoology',
/pok[eé]mon$/i,
/[^aeiou]ese$/i,
/deer$/i,
/fish$/i,
/measles$/i,
/o[iu]s$/i,
/pox$/i,
/sheep$/i,
/scissors$/i,
/pants$/i,
/shorts$/i,
/trousers$/i,
/jeans$/i,
]));