fox-inflector v2.0.5
Inflector
The library supplies functions to perform string manipulations with regard to uppercase/lowercase and singular/plural forms of words.
Find it in github
Installation
npm install fox-inflectorUsage
pluralize
Returns the plural of the word
pluralize('ox');       // oxensame function might be used as: (This is applicable for all functions)
'apple'.pluralize();   // applespluralized
Returns the plural of the word if second argument is greater then 1
pluralized('ox', 0);       // ox
pluralized('ox', 1);       // ox
pluralized('ox', 2);       // oxensame function might be used as: (This is applicable for all functions)
'apple'.pluralize();   // applessingularize
Returns the singular of the word
singularize('oxen');    // ox
singularize('apples');  // appletitleize
Converts an underscored or CamelCase word into a English sentence.
titleize('TestWord');   // Test wordcamelize
Returns given word as CamelCased Converts a word like "send_email" to "SendEmail". It will remove non alphanumeric character from the word, so "test#&case" will be converted to "TestCase"
camelize('test_word');  // TestWordcamel2words
Converts a CamelCase name into space-separated words. For example, 'PostTag' will be converted to 'Post Tag'.
camel2words('TestWord'); // Test Word
camel2words('testWord_Hello', false); // test word hellocamel2id
Converts a CamelCase name into an ID in lowercase. Words in the ID may be concatenated using the specified character (defaults to '-'). For example, 'PostTag' will be converted to 'post-tag'.
camel2id('TestWord');   // test-word
camel2id('testWord_Hello', '/');   // test/word/helloid2camel
Converts an ID into a CamelCase name.
Words in the ID separated by separator (defaults to '-') will be concatenated into a CamelCase name.
For example, 'post-tag' is converted to 'PostTag'.
id2camel('test-word');  // TestWord
id2camel('test-word-hello123-hi', '-');  // TestWordHello123Hiunderscore
Converts any "CamelCased" into an "underscored_word".
underscore('TestWord'); // test_word
underscore('TestWord-Hello123Hi'); // test_word-hello123_hihumanize
Returns a human-readable string from word
humanize('test_word_id');   // Test wordvariablize
Converts a word like "send_email" to "sendEmail" (Same as camelize but first char is in lowercase)
variablize('test_word_id');   // testWordIdtableize
Converts a class name to its table name (pluralized)
tableize('InfoPerson');   // info_peopleslug
Returns a string with all spaces converted to given replacement and non word characters removed. Maps special characters to ASCII
slug('test word # *@#id');   // test-word-id
slug('яблоко от яблони нe δàŁĒķỒ');   // yabloko-ot-yabloni-ne-dalekoclassify
Converts a table name to its class name. For example, converts "people" to "Person"
classify('test_words');   // TestWord
classify('language_japanese');   // LanguageJapaneseordinalize
Converts number to its ordinal English form. For example, converts 13 to 13th, 2 to 2nd ...
ordinalize(1);   // 1st
ordinalize(2);   // 1nd
ordinalize(3);   // 1rd
ordinalize(13);  // 13th