Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
inflection
Advanced tools
The inflection npm package is a utility library that provides functions for transforming words between singular, plural, camel case, underscore, human-readable, and other forms. It is useful for developers who need to manipulate and format strings, particularly in the context of programming languages that use different naming conventions for variables, classes, and database entries.
Pluralization and Singularization
Converts words from singular to plural and vice versa.
const inflection = require('inflection');
const singular = inflection.singularize('posts');
const plural = inflection.pluralize('post');
Camelizing and Underscoring
Converts strings to camel case or underscored form, useful for naming conventions in programming.
const inflection = require('inflection');
const camelized = inflection.camelize('message_properties');
const underscored = inflection.underscore('MessageProperties');
Humanizing
Transforms underscored strings into a human-readable form, often used for UI labels or titles.
const inflection = require('inflection');
const humanized = inflection.humanize('employee_id');
Titleizing
Capitalizes all the words and replaces some characters in the string to create a title.
const inflection = require('inflection');
const titleized = inflection.titleize('man from the boondocks');
Dasherizing
Replaces underscores with dashes in the string.
const inflection = require('inflection');
const dasherized = inflection.dasherize('puni_puni');
The 'pluralize' package is similar to inflection in that it provides pluralization and singularization of English nouns. It is a smaller and more focused library compared to inflection, which offers a broader range of string manipulation functions.
The 'change-case' package is a collection of utilities that allow for various string transformations, including camel case, snake case, title case, and more. It offers similar case transformation features to inflection but is part of a larger suite of case manipulation functions.
The 'underscore.string' package is an extension to the Underscore.js utility belt that provides additional string manipulation functions. It has some overlap with inflection in terms of string case transformations and humanizing strings, but it also includes a wide range of additional string functions not found in inflection.
A port of inflection-js to node.js module
inflection-js is a port of the functionality from Ruby on Rails' Active Support Inflection classes into Javascript. inflection
is a port of inflection-js
to node.js npm package. Instead of extending JavaScript native String object like inflection-js
does, inflection
separate the methods to a independent package to avoid unexpected behaviors.
Checkout package.json
for dependencies.
Install inflection through npm
npm install inflection
Require the module before using
var inflection = require( 'inflection' );
This lets us detect if an Array contains a given element.
arr
type: Array
desc: The subject array.
item
type: Object
desc: Object to locate in the Array.
fromIndex
type: Number
desc: Starts checking from this position in the Array.(optional)
compareFunc
type: Function
desc: Function used to compare Array item vs passed item.(optional)
var inflection = require( 'inflection' );
inflection.indexOf([ 'hi','there' ], 'guys' ); // === -1
inflection.indexOf([ 'hi','there' ], 'hi' ); // === 0
This function adds pluralization support to every String object.
str
type: String
desc: The subject string.
plural
type: String
desc: Overrides normal output with said String.(optional)
var inflection = require( 'inflection' );
inflection.pluralize( 'person' ); // === 'people'
inflection.pluralize( 'octopus' ); // === "octopi"
inflection.pluralize( 'Hat' ); // === 'Hats'
inflection.pluralize( 'person', 'guys' ); // === 'guys'
This function adds singularization support to every String object.
str
type: String
desc: The subject string.
singular
type: String
desc: Overrides normal output with said String.(optional)
var inflection = require( 'inflection' );
inflection.singularize( 'people' ); // === 'person'
inflection.singularize( 'octopi' ); // === "octopus"
inflection.singularize( 'Hats' ); // === 'Hat'
inflection.singularize( 'guys', 'person' ); // === 'person'
This function adds camelization support to every String object.
str
type: String
desc: The subject string.
lowFirstLetter
type: Boolean
desc: Default is to capitalize the first letter of the results. Passing true will lowercase it. (optional)
var inflection = require( 'inflection' );
inflection.camelize( 'message_properties' ); // === 'MessageProperties'
inflection.camelize( 'message_properties', true ); // === 'messageProperties'
This function adds underscore support to every String object.
str
type: String
desc: The subject string.
allUpperCase
type: Boolean
desc: Default is to lowercase and add underscore prefix
var inflection = require( 'inflection' );
inflection.underscore( 'MessageProperties' ); // === 'message_properties'
inflection.underscore( 'messageProperties' ); // === 'message_properties'
inflection.underscore( 'MP' ); // === 'm_p'
inflection.underscore( 'MP', true ); // === 'MP'
This function adds humanize support to every String object.
str
type: String
desc: The subject string.
lowFirstLetter
type: Boolean
desc: Default is to capitalize the first letter of the results. Passing true will lowercase it. (optional)
var inflection = require( 'inflection' );
inflection.humanize( 'message_properties' ); // === 'Message properties'
inflection.humanize( 'message_properties', true ); // === 'message properties'
This function adds capitalization support to every String object.
str
type: String
desc: The subject string.
var inflection = require( 'inflection' );
inflection.capitalize( 'message_properties' ); // === 'Message_properties'
inflection.capitalize( 'message properties', true ); // === 'Message properties'
This function adds dasherization support to every String object.
str
type: String
desc: The subject string.
var inflection = require( 'inflection' );
inflection.dasherize( 'message_properties' ); // === 'message-properties'
inflection.dasherize( 'Message Properties' ); // === 'Message-Properties'
This function adds titleize support to every String object.
str
type: String
desc: The subject string.
var inflection = require( 'inflection' );
inflection.titleize( 'message_properties' ); // === 'Message Properties'
inflection.titleize( 'message properties to keep' ); // === 'Message Properties to Keep'
This function adds demodulize support to every String object.
str
type: String
desc: The subject string.
var inflection = require( 'inflection' );
inflection.demodulize( 'Message::Bus::Properties' ); // === 'Properties'
This function adds tableize support to every String object.
str
type: String
desc: The subject string.
var inflection = require( 'inflection' );
inflection.tableize( 'MessageBusProperty' ); // === 'message_bus_properties'
This function adds classification support to every String object.
str
type: String
desc: The subject string.
var inflection = require( 'inflection' );
inflection.classify( 'message_bus_properties' ); // === 'MessageBusProperty'
This function adds foreign key support to every String object.
str
type: String
desc: The subject string.
lowFirstLetter
type: Boolean
desc: Default is to seperate id with an underbar at the end of the class name, you can pass true to skip it.(optional)
var inflection = require( 'inflection' );
inflection.foreign_key( 'MessageBusProperty' ); // === 'message_bus_property_id'
inflection.foreign_key( 'MessageBusProperty', true ); // === 'message_bus_propertyid'
This function adds ordinalize support to every String object.
str
type: String
desc: The subject string.
var inflection = require( 'inflection' );
inflection.ordinalize( 'the 1 pitch' ); // === 'the 1st pitch'
This function performs multiple inflection methods on a string.
str
type: String
desc: The subject string.
arr
type: Array
desc: An array of inflection methods.
var inflection = require( 'inflection' );
inflection.transform( 'all job', [ 'pluralize', 'capitalize', 'dasherize' ]); // === 'All-jobs'
(The MIT License)
Copyright (c) 2011 dreamerslab <ben@dreamerslab.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1.3.1 / 2013-12-12
Requirejs
FAQs
A port of inflection-js to node.js module
The npm package inflection receives a total of 2,950,278 weekly downloads. As such, inflection popularity was classified as popular.
We found that inflection demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.