![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
lodash-inflection
Advanced tools
Readme
This is a fork of Jeremy Ruppel underscore.inflection for lodash.
Another javascript inflector?!
I'll be the first to say it; this isn't the first port of ActiveSupport::Inflector to js. Not by a long shot. But I'll definitely take lodash mixins over extending String.prototype or other clunky implementations any day.
Also, this one has tests!
npm install lodash
npm install lodash-inflection
var _ = require("lodash");
_.mixin(require("lodash-inflection"));
The methods listed below are the ones you'll be using 99% of the time.
Signature: _.pluralize(word)
pluralize
pluralizes the string passed to it.
// functional style
_.pluralize('word'); // => 'words'
// object-oriented style
_('word').pluralize(); // => 'words'
It also can accept a number as the second parameter. If a number is provided, it will pluralize the word to match the number.
_('word').pluralize(0); // => 'words'
_('word').pluralize(1); // => 'word'
_('word').pluralize(1.5); // => 'words'
Optionally, you can pass true
as a third parameter. If found, this will include the count with the output.
_('word').pluralize(0, true); // => '0 words'
_('word').pluralize(1, true); // => '1 word'
Signature: _.singularize(word)
singularize
returns the singular version of the plural passed to it.
// functional style
_.singularize('words'); // => 'word'
// object-oriented style
_('words').singularize(); // => 'word'
Signature: _.gsub(word, rule, replacement)
gsub
is a method that is just slightly different than our standard String#replace
. The main differences are that it matches globally every time, and if no substitution is made it returns null
. It accepts a string for word
and replacement
, and rule
can be either a string or a regex.
// functional style
_.gsub('word', /wo/, 'ne'); // => 'nerd'
// object-oriented style
_('word').gsub(/wo/, 'ne'); // => 'nerd'
Signature: _.ordinalize(number)
ordinalize
adds an ordinal suffix to number
.
_.ordinalize(1); // => '1st'
_.ordinalize("5"); // => '5th'
_.ordinalize(11); // => '11th'
_.ordinalize(1033); // => '1033rd'
_.ordinalize(-15); // => '-15th'
Signature: _.titleize( words )
titleize
capitalizes the first letter of each word in the string words
. It preserves the existing whitespace.
_.titleize('banana'); // => 'Banana'
_.titleize('banana potato fork'); // => 'Banana Potato Fork'
_.titleize('banana potato\tfork'); // => 'Banana Potato\tFork'
Should you ever need to configure the Inflector beyond the defaults, use these methods to do so:
Signature: _.plural(rule, replacement)
plural
creates a new pluralization rule for the inflector. rule
can be either a string or a regex.
// functional style with explicit string
_.plural('axis', 'axes');
// object-oriented style with explicit string
_('axis').plural('axes');
// functional style with regex
_.plural(/(ax)is$/i, '$1es');
// object-oriented style with regex
_(/(ax)is$/i).plural('$1es');
Signature: _.singular(rule, replacement)
singular
creates a new singularization rule for the inflector. rule
can be either a string or a regex.
// functional style with explicit string
_.singular('data', 'datum');
// object-oriented style with explicit string
_('data').singular('datum');
// functional style with regex
_.singular(/(t)a$/i, '$1um');
// object-oriented style with regex
_(/(t)a$/i).singular('$1um');
Signature: _.irregular(singular, plural)
irregular
is a shortcut method to create both a pluralization and singularization rule for the word at the same time. You must supply both the singular form and the plural form as explicit strings.
// functional style
_.irregular('haxor', 'hax0rs!');
// object-oriented style
_('haxor').irregular('hax0rs!');
Signature: _.uncountable(word)
uncountable
creates a new uncountable rule for word
. Uncountable words do not get pluralized or singularized.
// functional style
_.uncountable('equipment');
// object-oriented style
_('equipment').uncountable();
Signature: _.resetInflections()
resetInflections
resets the inflector's rules to their initial state, clearing out any custom rules that have been added.
The Rails team for ActiveSupport
These other Inflector implementations:
Though no code was taken directly from them, they deserve plenty of props for doing it before me. If lodash isn't your thing, check them out!
65 Jeremy Ruppel
15 Daniel Perez
7 Landon Schropp
2 Johnathon Sanders
2 Seggy Umboh
1 Dayton Nolan
1 Joseph Spens
1 Kris Neuharth
1 Monica Olinescu
1 Sam Dornan
1 Shane Riley
1 bramski
1 maratfakhreev
1 trevor
FAQs
ActiveSupport::Inflector, for lodash!
The npm package lodash-inflection receives a total of 11,627 weekly downloads. As such, lodash-inflection popularity was classified as popular.
We found that lodash-inflection 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.