
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
underscore.inflections
Advanced tools
Port of ActiveSupport::Inflector::Inflections for underscore.js
Port of ActiveSupport::Inflector::Inflections for Underscore.js.
Works with browser or Node.js.
I created this underscore mixin after trying out every other inflection library out there. I've created this as a direct port of Rails' version as much as possible.
Note that right now, this only handles methods found in ActiveSupport::Inflector::Inflections since that's all I need right now. I may eventually split this out into separate inflector mixins that match all of ActiveSupport's.
Include both underscore.js and underscore.inflections on your page:
<script src="underscore.js" type="text/javascript"></script>
<script src="underscore.inflections.js" type="text/javascript"></script>
First, install the mixin through npm:
npm install underscore.inflections
Require underscore.js and underscore.inflections:
var _ = require('underscore');
_.mixin(require('underscore.inflections'));
Note: When using underscore in Node's REPL, be sure to choose a variable other than _
, as that is a special symbol used for showing the last return value.
Converts a word to its singular form.
Examples:
_.singularize('posts'); //=> 'post'
_.singularize('octopi'); //=> 'octopus'
_.singularize('sheep'); //=> 'sheep'
_.singularize('words'); //=> 'words'
Converts a word to its pluralized form.
Examples:
_.pluralize('post'); //=> 'posts'
_.pluralize('octopus'); //=> 'octopi'
_.pluralize('sheep'); //=> 'sheep'
_.pluralize('words'); //=> 'words'
Adds a rule for singularizing a word.
Example:
_.singular(/^(ox)en/i, '\1');
Adds a rule for pluralizing a word.
Example:
_.plural(/^(ox)$/i, '\1en');
Adds a rule for an irregular word.
Example:
_.irregular('person', 'people');
Adds a rule for an uncountable word or words.
Example:
_.uncountable(['fish', 'sheep']);
Makes the following inflection methods aware of acronyms: _.camelize, _.underscore, _.humanize, _.titleize See inflections_test for a full specifications of the subtleties
_.acronym("FBI");
_.camelize("fbi_file"); //=> 'FBIFile'
_.underscore("FBIFile"); //=> 'fbi_file'
Example:
_.camelize('make_me_tall'); //=> 'MakeMeTall'
When passed false as second parameter it does not capitalize the first word
Example:
_.camelize('make_me_tall', false); //=> 'makeMeTall'
Separate camel cased strings with underscores
Example:
_.underscore('INeedSomeSpace'); //=> 'i_need_some_space'
Format underscored strings for human friendly consumption
Example:
_.humanize('i_just_want_to_be_understood'); //=> 'I just want to be understood'
You can also add humanizing rules by calling _.human
Example:
_.human(/_cnt$/,'_count');
_.humanize('jargon_cnt'); //=> 'Jargon count'
Title case a underscored or camel cased string
Example:
_.titleize('three_blind_mice'); //=> 'Three Blind Mice'
_.titleize('JackAndJill'); //=> 'Jack And Jill'
MIT. See LICENSE
.
FAQs
Port of ActiveSupport::Inflector::Inflections for underscore.js
The npm package underscore.inflections receives a total of 9,748 weekly downloads. As such, underscore.inflections popularity was classified as popular.
We found that underscore.inflections demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.