Socket
Socket
Sign inDemoInstall

inflection

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inflection - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

15

lib/inflection.d.ts

@@ -10,17 +10,2 @@ /*!

/**
* This lets us detect if an Array contains a given element.
* @param arr The subject array.
* @param item Object to locate in the Array.
* @param fromIndex Starts checking from this position in the Array.(optional)
* @param compareFunc Function used to compare Array item vs passed item.(optional)
* @returns Return index position in the Array of the passed item.
* @example
*
* const inflection = require( 'inflection' );
*
* inflection.indexOf([ 'hi','there' ], 'guys' ); // === -1
* inflection.indexOf([ 'hi','there' ], 'hi' ); // === 0
*/
export declare function indexOf<T>(arr: T[], item: T, fromIndex?: number, compareFunc?: (el: T, arg1: T) => boolean): number;
/**
* This function adds pluralization support to every String object.

@@ -27,0 +12,0 @@ * @param str The subject string.

52

lib/inflection.js

@@ -11,3 +11,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.transform = exports.ordinalize = exports.foreignKey = exports.classify = exports.tableize = exports.demodulize = exports.titleize = exports.dasherize = exports.capitalize = exports.humanize = exports.underscore = exports.camelize = exports.inflect = exports.singularize = exports.pluralize = exports.indexOf = void 0;
exports.transform = exports.ordinalize = exports.foreignKey = exports.classify = exports.tableize = exports.demodulize = exports.titleize = exports.dasherize = exports.capitalize = exports.humanize = exports.underscore = exports.camelize = exports.inflect = exports.singularize = exports.pluralize = void 0;
/**

@@ -566,16 +566,14 @@ * @description This is a list of nouns that use the same form for both singular and plural.

if (override) {
str = override;
return override;
}
else {
const ignore = indexOf(skip, str.toLowerCase()) > -1;
if (!ignore) {
const j = rules.length;
for (let i = 0; i < j; i++) {
if (str.match(rules[i][0])) {
const replaceRule = rules[i][1];
if (replaceRule !== undefined) {
str = str.replace(rules[i][0], replaceRule);
}
break;
if (skip.includes(str.toLocaleLowerCase())) {
return str;
}
for (const rule of rules) {
if (str.match(rule[0])) {
if (rule[1] !== undefined) {
return str.replace(rule[0], rule[1]);
}
return str;
}

@@ -587,30 +585,2 @@ }

/**
* This lets us detect if an Array contains a given element.
* @param arr The subject array.
* @param item Object to locate in the Array.
* @param fromIndex Starts checking from this position in the Array.(optional)
* @param compareFunc Function used to compare Array item vs passed item.(optional)
* @returns Return index position in the Array of the passed item.
* @example
*
* const inflection = require( 'inflection' );
*
* inflection.indexOf([ 'hi','there' ], 'guys' ); // === -1
* inflection.indexOf([ 'hi','there' ], 'hi' ); // === 0
*/
function indexOf(arr, item, fromIndex, compareFunc) {
if (!fromIndex) {
fromIndex = -1;
}
let index = -1;
for (let i = fromIndex; i < arr.length; i++) {
if (arr[i] === item || (compareFunc && compareFunc(arr[i], item))) {
index = i;
break;
}
}
return index;
}
exports.indexOf = indexOf;
/**
* This function adds pluralization support to every String object.

@@ -822,3 +792,3 @@ * @param str The subject string.

for (let k = 0; k < l; k++) {
if (indexOf(nonTitlecasedWords, d[k].toLowerCase()) < 0) {
if (nonTitlecasedWords.indexOf(d[k].toLowerCase()) < 0) {
d[k] = capitalize(d[k]);

@@ -825,0 +795,0 @@ }

{
"name": "inflection",
"version": "2.0.0",
"version": "2.0.1",
"description": "A port of inflection-js to node.js module",

@@ -95,4 +95,4 @@ "keywords": [

"devDependencies": {
"typescript": "^4.8.3",
"vitest": "^0.25.2"
"typescript": "^4.9.4",
"vitest": "^0.26.2"
},

@@ -99,0 +99,0 @@ "main": "./lib/inflection.js",

# inflection
A port of inflection-js to node.js module
A package to transform english strings into other forms like the plural form, singular form, camelCase form, etc.
<a href="https://www.npmjs.com/package/inflection"><img src="https://img.shields.io/npm/v/inflection" alt="NPM Version" /></a>
## Description
[inflection-js](http://code.google.com/p/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](http://wonko.com/post/extending-javascript-natives) String object like `inflection-js` does, `inflection` separate the methods to a independent package to avoid unexpected behaviors.
This package was originally a port of [inflection-js](http://code.google.com/p/inflection-js/), which is a port of the functionality from Ruby on Rails' Active Support Inflection classes into Javascript.
Note: This library uses [Wiktionary](http://en.wiktionary.org) as its reference.
## Requires

@@ -19,4 +17,2 @@

## Angular Support

@@ -26,4 +22,2 @@

## Meteor Support

@@ -33,4 +27,2 @@

## Installation

@@ -40,9 +32,6 @@

npm install inflection
npm install inflection
## API
- inflection.indexOf( arr, item, from_index, compare_func );
- inflection.pluralize( str, plural );

@@ -64,4 +53,2 @@ - inflection.singularize( str, singular );

## Usage

@@ -71,41 +58,4 @@

var inflection = require( 'inflection' );
const inflection = require( 'inflection' );
### inflection.indexOf( arr, item, from_index, compare_func );
This lets us detect if an Array contains a given element.
#### Arguments
> arr
type: Array
desc: The subject array.
> item
type: Object
desc: Object to locate in the Array.
> from_index
type: Number
desc: Starts checking from this position in the Array.(optional)
> compare_func
type: Function
desc: Function used to compare Array item vs passed item.(optional)
#### Example code
var inflection = require( 'inflection' );
inflection.indexOf([ 'hi','there' ], 'guys' ); // === -1
inflection.indexOf([ 'hi','there' ], 'hi' ); // === 0
### inflection.pluralize( str, plural );

@@ -119,21 +69,19 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
> plural
type: String
desc: Overrides normal output with said String.(optional)
type: String
desc: Overrides normal output with said String.(optional)
#### Example code
var inflection = require( 'inflection' );
var inflection = require( 'inflection' );
inflection.pluralize( 'person' ); // === 'people'
inflection.pluralize( 'octopus' ); // === "octopi"
inflection.pluralize( 'Hat' ); // === 'Hats'
inflection.pluralize( 'person', 'guys' ); // === 'guys'
inflection.pluralize( 'person' ); // === 'people'
inflection.pluralize( 'octopus' ); // === "octopi"
inflection.pluralize( 'Hat' ); // === 'Hats'
inflection.pluralize( 'person', 'guys' ); // === 'guys'
### inflection.singularize( str, singular );

@@ -147,21 +95,19 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
> singular
type: String
desc: Overrides normal output with said String.(optional)
type: String
desc: Overrides normal output with said String.(optional)
#### Example code
var inflection = require( 'inflection' );
var inflection = require( 'inflection' );
inflection.singularize( 'people' ); // === 'person'
inflection.singularize( 'octopi' ); // === "octopus"
inflection.singularize( 'Hats' ); // === 'Hat'
inflection.singularize( 'guys', 'person' ); // === 'person'
inflection.singularize( 'people' ); // === 'person'
inflection.singularize( 'octopi' ); // === "octopus"
inflection.singularize( 'Hats' ); // === 'Hat'
inflection.singularize( 'guys', 'person' ); // === 'person'
### inflection.inflect( str, count, singular, plural );

@@ -175,34 +121,33 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
> count
type: Number
desc: The number to base pluralization off of.
type: Number
desc: The number to base pluralization off of.
> singular
type: String
desc: Overrides normal output with said String.(optional)
type: String
desc: Overrides normal output with said String.(optional)
> plural
type: String
desc: Overrides normal output with said String.(optional)
type: String
desc: Overrides normal output with said String.(optional)
#### Example code
var inflection = require( 'inflection' );
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.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 );

@@ -216,19 +161,17 @@

type: String
desc: The subject string.
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)
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' );
var inflection = require( 'inflection' );
inflection.camelize( 'message_properties' ); // === 'MessageProperties'
inflection.camelize( 'message_properties', true ); // === 'messageProperties'
inflection.camelize( 'message_properties' ); // === 'MessageProperties'
inflection.camelize( 'message_properties', true ); // === 'messageProperties'
### inflection.underscore( str, all_upper_case );

@@ -242,23 +185,19 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
> all_upper_case
type: Boolean
desc: Default is to lowercase and add underscore prefix
type: Boolean
desc: Default is to lowercase and add underscore prefix
#### Example code
var inflection = require( 'inflection' );
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.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 );

@@ -272,19 +211,17 @@

type: String
desc: The subject string.
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)
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' );
var inflection = require( 'inflection' );
inflection.humanize( 'message_properties' ); // === 'Message properties'
inflection.humanize( 'message_properties', true ); // === 'message properties'
inflection.humanize( 'message_properties' ); // === 'Message properties'
inflection.humanize( 'message_properties', true ); // === 'message properties'
### inflection.capitalize( str );

@@ -298,14 +235,12 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
#### Example code
var inflection = require( 'inflection' );
var inflection = require( 'inflection' );
inflection.capitalize( 'message_properties' ); // === 'Message_properties'
inflection.capitalize( 'message properties', true ); // === 'Message properties'
inflection.capitalize( 'message_properties' ); // === 'Message_properties'
inflection.capitalize( 'message properties', true ); // === 'Message properties'
### inflection.dasherize( str );

@@ -319,14 +254,12 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
#### Example code
var inflection = require( 'inflection' );
var inflection = require( 'inflection' );
inflection.dasherize( 'message_properties' ); // === 'message-properties'
inflection.dasherize( 'Message Properties' ); // === 'Message-Properties'
inflection.dasherize( 'message_properties' ); // === 'message-properties'
inflection.dasherize( 'Message Properties' ); // === 'Message-Properties'
### inflection.titleize( str );

@@ -340,14 +273,12 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
#### Example code
var inflection = require( 'inflection' );
var inflection = require( 'inflection' );
inflection.titleize( 'message_properties' ); // === 'Message Properties'
inflection.titleize( 'message properties to keep' ); // === 'Message Properties to Keep'
inflection.titleize( 'message_properties' ); // === 'Message Properties'
inflection.titleize( 'message properties to keep' ); // === 'Message Properties to Keep'
### inflection.demodulize( str );

@@ -361,13 +292,11 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
#### Example code
var inflection = require( 'inflection' );
var inflection = require( 'inflection' );
inflection.demodulize( 'Message::Bus::Properties' ); // === 'Properties'
inflection.demodulize( 'Message::Bus::Properties' ); // === 'Properties'
### inflection.tableize( str );

@@ -381,13 +310,11 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
#### Example code
var inflection = require( 'inflection' );
var inflection = require( 'inflection' );
inflection.tableize( 'MessageBusProperty' ); // === 'message_bus_properties'
inflection.tableize( 'MessageBusProperty' ); // === 'message_bus_properties'
### inflection.classify( str );

@@ -401,13 +328,11 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
#### Example code
var inflection = require( 'inflection' );
var inflection = require( 'inflection' );
inflection.classify( 'message_bus_properties' ); // === 'MessageBusProperty'
inflection.classify( 'message_bus_properties' ); // === 'MessageBusProperty'
### inflection.foreign_key( str, drop_id_ubar );

@@ -421,19 +346,17 @@

type: String
desc: The subject string.
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)
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' );
var inflection = require( 'inflection' );
inflection.foreign_key( 'MessageBusProperty' ); // === 'message_bus_property_id'
inflection.foreign_key( 'MessageBusProperty', true ); // === 'message_bus_propertyid'
inflection.foreign_key( 'MessageBusProperty' ); // === 'message_bus_property_id'
inflection.foreign_key( 'MessageBusProperty', true ); // === 'message_bus_propertyid'
### inflection.ordinalize( str );

@@ -447,13 +370,11 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
#### Example code
var inflection = require( 'inflection' );
var inflection = require( 'inflection' );
inflection.ordinalize( 'the 1 pitch' ); // === 'the 1st pitch'
inflection.ordinalize( 'the 1 pitch' ); // === 'the 1st pitch'
### inflection.transform( str, arr );

@@ -467,18 +388,16 @@

type: String
desc: The subject string.
type: String
desc: The subject string.
> arr
type: Array
desc: An array of inflection methods.
type: Array
desc: An array of inflection methods.
#### Example code
var inflection = require( 'inflection' );
var inflection = require( 'inflection' );
inflection.transform( 'all job', [ 'pluralize', 'capitalize', 'dasherize' ]); // === 'All-jobs'
inflection.transform( 'all job', [ 'pluralize', 'capitalize', 'dasherize' ]); // === 'All-jobs'
## Credit

@@ -502,3 +421,2 @@

## License

@@ -505,0 +423,0 @@

@@ -607,17 +607,15 @@ /*!

if (override) {
str = override;
return override;
} else {
const ignore = indexOf(skip, str.toLowerCase()) > -1;
if (skip.includes(str.toLocaleLowerCase())) {
return str;
}
if (!ignore) {
const j = rules.length;
for (const rule of rules) {
if (str.match(rule[0])) {
if (rule[1] !== undefined) {
return str.replace(rule[0], rule[1]);
}
for (let i = 0; i < j; i++) {
if (str.match(rules[i][0])) {
const replaceRule = rules[i][1];
if (replaceRule !== undefined) {
str = str.replace(rules[i][0], replaceRule);
}
break;
}
return str;
}

@@ -631,38 +629,2 @@ }

/**
* This lets us detect if an Array contains a given element.
* @param arr The subject array.
* @param item Object to locate in the Array.
* @param fromIndex Starts checking from this position in the Array.(optional)
* @param compareFunc Function used to compare Array item vs passed item.(optional)
* @returns Return index position in the Array of the passed item.
* @example
*
* const inflection = require( 'inflection' );
*
* inflection.indexOf([ 'hi','there' ], 'guys' ); // === -1
* inflection.indexOf([ 'hi','there' ], 'hi' ); // === 0
*/
export function indexOf<T>(
arr: T[],
item: T,
fromIndex?: number,
compareFunc?: (el: T, arg1: T) => boolean
) {
if (!fromIndex) {
fromIndex = -1;
}
let index = -1;
for (let i = fromIndex; i < arr.length; i++) {
if (arr[i] === item || (compareFunc && compareFunc(arr[i], item))) {
index = i;
break;
}
}
return index;
}
/**
* This function adds pluralization support to every String object.

@@ -890,3 +852,3 @@ * @param str The subject string.

for (let k = 0; k < l; k++) {
if (indexOf(nonTitlecasedWords, d[k].toLowerCase()) < 0) {
if (nonTitlecasedWords.indexOf(d[k].toLowerCase()) < 0) {
d[k] = capitalize(d[k]);

@@ -893,0 +855,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc