Installations
npm install inflection
Developer
dreamerslab
Developer Guide
Module System
CommonJS
Min. Node Version
>=18.0.0
Typescript Support
Yes
Node Version
20.6.1
NPM Version
9.8.1
Statistics
554 Stars
234 Commits
46 Forks
16 Watching
4 Branches
22 Contributors
Updated on 02 Nov 2024
Bundle Size
9.82 kB
Minified
3.28 kB
Minified + Gzipped
Languages
TypeScript (58.28%)
JavaScript (41.72%)
Total Downloads
Cumulative downloads
Total Downloads
758,133,519
Last day
-1.4%
616,761
Compared to previous day
Last week
1.1%
3,324,785
Compared to previous week
Last month
6.6%
13,938,787
Compared to previous month
Last year
12.2%
159,069,055
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
2
inflection
A package to transform english strings into other forms like the plural form, singular form, camelCase form, etc.
Description
This package was originally a port of inflection-js, which is a port of the functionality from Ruby on Rails' Active Support Inflection classes into Javascript.
Note: This library uses Wiktionary as its reference.
Requires
Checkout package.json
for dependencies.
Angular Support
Checkout ngInflection from konsumer
Meteor Support
Checkout Meteor Inflector from Veaceslav Cotruta
Installation
Install inflection through npm
npm install inflection
API
- inflection.pluralize( str, plural );
- inflection.singularize( str, singular );
- inflection.inflect( str, count, singular, plural );
- inflection.camelize( str, low_first_letter );
- inflection.underscore( str, all_upper_case );
- inflection.humanize( str, low_first_letter );
- inflection.capitalize( str );
- inflection.dasherize( str );
- inflection.titleize( str );
- inflection.demodulize( str );
- inflection.tableize( str );
- inflection.classify( str );
- inflection.foreign_key( str, drop_id_ubar );
- inflection.ordinalize( str );
- inflection.transform( str, arr );
Usage
Require the module before using
const inflection = require( 'inflection' );
inflection.pluralize( str, plural );
This function adds pluralization support to every String object.
Arguments
str
type: String
desc: The subject string.
plural
type: String
desc: Overrides normal output with said String.(optional)
Example code
var inflection = require( 'inflection' );
inflection.pluralize( 'person' ); // === 'people'
inflection.pluralize( 'octopus' ); // === "octopi"
inflection.pluralize( 'Hat' ); // === 'Hats'
inflection.pluralize( 'person', 'guys' ); // === 'guys'
inflection.singularize( str, singular );
This function adds singularization support to every String object.
Arguments
str
type: String
desc: The subject string.
singular
type: String
desc: Overrides normal output with said String.(optional)
Example code
var inflection = require( 'inflection' );
inflection.singularize( 'people' ); // === 'person'
inflection.singularize( 'octopi' ); // === "octopus"
inflection.singularize( 'Hats' ); // === 'Hat'
inflection.singularize( 'guys', 'person' ); // === 'person'
inflection.inflect( str, count, singular, plural );
This function will pluralize or singularlize a String appropriately based on an integer value.
Arguments
str
type: String
desc: The subject string.
count
type: Number
desc: The number to base pluralization off of.
singular
type: String
desc: Overrides normal output with said String.(optional)
plural
type: String
desc: Overrides normal output with said String.(optional)
Example code
var inflection = require( 'inflection' );
inflection.inflect( 'people', 1 ); // === 'person'
inflection.inflect( 'octopi', 1 ); // === 'octopus'
inflection.inflect( 'Hats', 1 ); // === 'Hat'
inflection.inflect( 'guys', 1 , 'person' ); // === 'person'
inflection.inflect( 'person', 2 ); // === 'people'
inflection.inflect( 'octopus', 2 ); // === 'octopi'
inflection.inflect( 'Hat', 2 ); // === 'Hats'
inflection.inflect( 'person', 2, null, 'guys' ); // === 'guys'
inflection.camelize( str, low_first_letter );
This function transforms String object from underscore to camelcase.
Arguments
str
type: String
desc: The subject string.
low_first_letter
type: Boolean
desc: Default is to capitalize the first letter of the results. Passing true will lowercase it. (optional)
Example code
var inflection = require( 'inflection' );
inflection.camelize( 'message_properties' ); // === 'MessageProperties'
inflection.camelize( 'message_properties', true ); // === 'messageProperties'
inflection.underscore( str, all_upper_case );
This function transforms String object from camelcase to underscore.
Arguments
str
type: String
desc: The subject string.
all_upper_case
type: Boolean
desc: Default is to lowercase and add underscore prefix
Example code
var inflection = require( 'inflection' );
inflection.underscore( 'MessageProperties' ); // === 'message_properties'
inflection.underscore( 'messageProperties' ); // === 'message_properties'
inflection.underscore( 'MP' ); // === 'm_p'
inflection.underscore( 'MP', true ); // === 'MP'
inflection.humanize( str, low_first_letter );
This function adds humanize support to every String object.
Arguments
str
type: String
desc: The subject string.
low_first_letter
type: Boolean
desc: Default is to capitalize the first letter of the results. Passing true will lowercase it. (optional)
Example code
var inflection = require( 'inflection' );
inflection.humanize( 'message_properties' ); // === 'Message properties'
inflection.humanize( 'message_properties', true ); // === 'message properties'
inflection.capitalize( str );
This function adds capitalization support to every String object.
Arguments
str
type: String
desc: The subject string.
Example code
var inflection = require( 'inflection' );
inflection.capitalize( 'message_properties' ); // === 'Message_properties'
inflection.capitalize( 'message properties', true ); // === 'Message properties'
inflection.dasherize( str );
This function replaces underscores with dashes in the string.
Arguments
str
type: String
desc: The subject string.
Example code
var inflection = require( 'inflection' );
inflection.dasherize( 'message_properties' ); // === 'message-properties'
inflection.dasherize( 'Message Properties' ); // === 'Message-Properties'
inflection.titleize( str );
This function adds titleize support to every String object.
Arguments
str
type: String
desc: The subject string.
Example code
var inflection = require( 'inflection' );
inflection.titleize( 'message_properties' ); // === 'Message Properties'
inflection.titleize( 'message properties to keep' ); // === 'Message Properties to Keep'
inflection.demodulize( str );
This function adds demodulize support to every String object.
Arguments
str
type: String
desc: The subject string.
Example code
var inflection = require( 'inflection' );
inflection.demodulize( 'Message::Bus::Properties' ); // === 'Properties'
inflection.tableize( str );
This function adds tableize support to every String object.
Arguments
str
type: String
desc: The subject string.
Example code
var inflection = require( 'inflection' );
inflection.tableize( 'MessageBusProperty' ); // === 'message_bus_properties'
inflection.classify( str );
This function adds classification support to every String object.
Arguments
str
type: String
desc: The subject string.
Example code
var inflection = require( 'inflection' );
inflection.classify( 'message_bus_properties' ); // === 'MessageBusProperty'
inflection.foreign_key( str, drop_id_ubar );
This function adds foreign key support to every String object.
Arguments
str
type: String
desc: The subject string.
low_first_letter
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)
Example code
var inflection = require( 'inflection' );
inflection.foreign_key( 'MessageBusProperty' ); // === 'message_bus_property_id'
inflection.foreign_key( 'MessageBusProperty', true ); // === 'message_bus_propertyid'
inflection.ordinalize( str );
This function adds ordinalize support to every String object.
Arguments
str
type: String
desc: The subject string.
Example code
var inflection = require( 'inflection' );
inflection.ordinalize( 'the 1 pitch' ); // === 'the 1st pitch'
inflection.transform( str, arr );
This function performs multiple inflection methods on a string.
Arguments
str
type: String
desc: The subject string.
arr
type: Array
desc: An array of inflection methods.
Example code
var inflection = require( 'inflection' );
inflection.transform( 'all job', [ 'pluralize', 'capitalize', 'dasherize' ]); // === 'All-jobs'
Credit
- Ryan Schuft ryan.schuft@gmail.com
- Lance Pollard lancejpollard@gmail.com (Browser support)
- Dane O'Connor dane.oconnor@gmail.com
- brandondewitt
- luk3thomas
- Marcel Klehr
- Raymond Feng
- Kane Cohen kanecohen@gmail.com
- Gianni Chiappetta gianni@runlevel6.org
- Eric Brody
- overlookmotel
- Patrick Mowrer
- Greger Olsson
- Jason Crawford jason@jasoncrawford.org
- Ray Myers ray.myers@gmail.com
License
(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.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
4 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
Reason
Found 0/22 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/dreamerslab/node.inflection/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/dreamerslab/node.inflection/test.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:10
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 9 are checked with a SAST tool
Score
3.1
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to inflection
@types/inflection
TypeScript definitions for inflection
czech-inflection
Inflection of Czech words
@graphile/simplify-inflection
Simplifies the graphile-build/graphile-build-pg inflection to trim the `ByFooIdAndBarId` from relations, etc
nginflection
Angular filters for inflection