Skip to content

Commit

Permalink
Merge pull request #109 from nick-w-nick/readme-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
p-kuen authored Jan 28, 2025
2 parents a3ca9b9 + 977a328 commit 9fb200b
Showing 1 changed file with 115 additions and 104 deletions.
219 changes: 115 additions & 104 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,30 @@ Checkout [Meteor Inflector](https://github.com/katrotz/meteor-inflector) from [V
## Installation

Install inflection through npm

npm install inflection

```bash
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 );
- [pluralize(str, plural)](#pluralizestr-plural)
- [singularize(str, singular)](#singularizestr-singular)
- [inflect(str, count, singular, plural)](#inflectstr-count-singular-plural)
- [camelize(str, low_first_letter)](#camelizestr-low_first_letter)
- [underscore(str, all_upper_case)](#underscorestr-all_upper_case)
- [humanize(str, low_first_letter)](#humanizestr-low_first_letter)
- [capitalize(str)](#capitalizestr)
- [dasherize(str)](#dasherizestr)
- [titleize(str)](#titleizestr)
- [demodulize(str)](#demodulizestr)
- [tableize(str)](#tableizestr)
- [classify(str)](#classifystr)
- [foreign_key(str, drop_id_ubar)](#foreign_keystr-drop_id_ubar)
- [ordinalize(str)](#ordinalizestr)
- [transform(str, arr)](#transformstr-arr)

## Usage

> Require the module before using
const inflection = require( 'inflection' );

### inflection.pluralize( str, plural );
### pluralize(str, plural)

This function adds pluralization support to every String object.

Expand All @@ -69,15 +65,16 @@ This function adds pluralization support to every String object.
desc: Overrides normal output with said String.(optional)

#### Example code
```js
const { pluralize } = require('inflection');

var inflection = require( 'inflection' );

inflection.pluralize( 'person' ); // === 'people'
inflection.pluralize( 'octopus' ); // === "octopi"
inflection.pluralize( 'Hat' ); // === 'Hats'
inflection.pluralize( 'person', 'guys' ); // === 'guys'
pluralize('person'); // === 'people'
pluralize('octopus'); // === "octopi"
pluralize('Hat'); // === 'Hats'
pluralize('person', 'guys'); // === 'guys'
```

### inflection.singularize( str, singular );
### singularize(str, singular)

This function adds singularization support to every String object.

Expand All @@ -94,15 +91,16 @@ This function adds singularization support to every String object.
desc: Overrides normal output with said String.(optional)

#### Example code
```js
const { singularize } = require('inflection');

var inflection = require( 'inflection' );
singularize('people'); // === 'person'
singularize('octopi'); // === "octopus"
singularize('Hats'); // === 'Hat'
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 );
### inflect(str, count, singular, plural)

This function will pluralize or singularlize a String appropriately based on an integer value.

Expand All @@ -129,19 +127,20 @@ This function will pluralize or singularlize a String appropriately based on an
desc: Overrides normal output with said String.(optional)

#### Example code
```js
const { inflect } = 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'
inflect('people', 1); // === 'person'
inflect('octopi', 1); // === 'octopus'
inflect('Hats', 1); // === 'Hat'
inflect('guys', 1 , 'person'); // === 'person'
inflect('person', 2); // === 'people'
inflect('octopus', 2); // === 'octopi'
inflect('Hat', 2); // === 'Hats'
inflect('person', 2, null, 'guys'); // === 'guys'
```

### inflection.camelize( str, low_first_letter );
### camelize(str, low_first_letter)

This function transforms String object from underscore to camelcase.

Expand All @@ -158,13 +157,14 @@ This function transforms String object from underscore to camelcase.
desc: Default is to capitalize the first letter of the results. Passing true will lowercase it. (optional)

#### Example code
```js
const { camelize } = require('inflection');

var inflection = require( 'inflection' );

inflection.camelize( 'message_properties' ); // === 'MessageProperties'
inflection.camelize( 'message_properties', true ); // === 'messageProperties'
camelize('message_properties'); // === 'MessageProperties'
camelize('message_properties', true); // === 'messageProperties'
```

### inflection.underscore( str, all_upper_case );
### underscore(str, all_upper_case)

This function transforms String object from camelcase to underscore.

Expand All @@ -181,15 +181,16 @@ This function transforms String object from camelcase to underscore.
desc: Default is to lowercase and add underscore prefix

#### Example code
```js
const { underscore } = require('inflection');

var inflection = require( 'inflection' );
underscore('MessageProperties'); // === 'message_properties'
underscore('messageProperties'); // === 'message_properties'
underscore('MP'); // === 'm_p'
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 );
### humanize(str, low_first_letter)

This function adds humanize support to every String object.

Expand All @@ -206,13 +207,14 @@ This function adds humanize support to every String object.
desc: Default is to capitalize the first letter of the results. Passing true will lowercase it. (optional)

#### Example code
```js
const { humanize } = require('inflection');

var inflection = require( 'inflection' );

inflection.humanize( 'message_properties' ); // === 'Message properties'
inflection.humanize( 'message_properties', true ); // === 'message properties'
humanize('message_properties'); // === 'Message properties'
humanize('message_properties', true); // === 'message properties'
```

### inflection.capitalize( str );
### capitalize(str)

This function adds capitalization support to every String object.

Expand All @@ -224,13 +226,14 @@ This function adds capitalization support to every String object.
desc: The subject string.

#### Example code
```js
const { capitalize } = require('inflection');

var inflection = require( 'inflection' );
capitalize('message_properties'); // === 'Message_properties'
capitalize('message properties', true); // === 'Message properties'
```

inflection.capitalize( 'message_properties' ); // === 'Message_properties'
inflection.capitalize( 'message properties', true ); // === 'Message properties'

### inflection.dasherize( str );
### dasherize(str)

This function replaces underscores with dashes in the string.

Expand All @@ -242,13 +245,14 @@ This function replaces underscores with dashes in the string.
desc: The subject string.

#### Example code
```js
const { dasherize } = require('inflection');

var inflection = require( 'inflection' );

inflection.dasherize( 'message_properties' ); // === 'message-properties'
inflection.dasherize( 'Message Properties' ); // === 'Message-Properties'
dasherize('message_properties'); // === 'message-properties'
dasherize('Message Properties'); // === 'Message-Properties'
```

### inflection.titleize( str );
### titleize(str)

This function adds titleize support to every String object.

Expand All @@ -260,13 +264,14 @@ This function adds titleize support to every String object.
desc: The subject string.

#### Example code
```js
const { titleize } = require('inflection');

var inflection = require( 'inflection' );

inflection.titleize( 'message_properties' ); // === 'Message Properties'
inflection.titleize( 'message properties to keep' ); // === 'Message Properties to Keep'
titleize('message_properties'); // === 'Message Properties'
titleize('message properties to keep'); // === 'Message Properties to Keep'
```

### inflection.demodulize( str );
### demodulize(str)

This function adds demodulize support to every String object.

Expand All @@ -278,12 +283,13 @@ This function adds demodulize support to every String object.
desc: The subject string.

#### Example code
```js
const { demodulize } = require('inflection');

var inflection = require( 'inflection' );
demodulize('Message::Bus::Properties'); // === 'Properties'
```

inflection.demodulize( 'Message::Bus::Properties' ); // === 'Properties'

### inflection.tableize( str );
### tableize(str)

This function adds tableize support to every String object.

Expand All @@ -295,12 +301,13 @@ This function adds tableize support to every String object.
desc: The subject string.

#### Example code
```js
const { tableize } = require('inflection');

var inflection = require( 'inflection' );

inflection.tableize( 'MessageBusProperty' ); // === 'message_bus_properties'
tableize('MessageBusProperty'); // === 'message_bus_properties'
```

### inflection.classify( str );
### classify(str)

This function adds classification support to every String object.

Expand All @@ -312,12 +319,13 @@ This function adds classification support to every String object.
desc: The subject string.

#### Example code
```js
const { classify } = require('inflection');

var inflection = require( 'inflection' );
classify('message_bus_properties'); // === 'MessageBusProperty'
```

inflection.classify( 'message_bus_properties' ); // === 'MessageBusProperty'

### inflection.foreign_key( str, drop_id_ubar );
### foreign_key(str, drop_id_ubar)

This function adds foreign key support to every String object.

Expand All @@ -334,13 +342,14 @@ This function adds foreign key support to every String object.
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
```js
const { foreign_key } = require('inflection');

var inflection = require( 'inflection' );

inflection.foreign_key( 'MessageBusProperty' ); // === 'message_bus_property_id'
inflection.foreign_key( 'MessageBusProperty', true ); // === 'message_bus_propertyid'
foreign_key('MessageBusProperty'); // === 'message_bus_property_id'
foreign_key('MessageBusProperty', true); // === 'message_bus_propertyid'
```

### inflection.ordinalize( str );
### ordinalize(str)

This function adds ordinalize support to every String object.

Expand All @@ -352,12 +361,13 @@ This function adds ordinalize support to every String object.
desc: The subject string.

#### Example code
```js
const { ordinalize } = require('inflection');

var inflection = require( 'inflection' );
ordinalize('the 1 pitch'); // === 'the 1st pitch'
```

inflection.ordinalize( 'the 1 pitch' ); // === 'the 1st pitch'

### inflection.transform( str, arr );
### transform(str, arr)

This function performs multiple inflection methods on a string.

Expand All @@ -374,10 +384,11 @@ This function performs multiple inflection methods on a string.
desc: An array of inflection methods.

#### Example code
```js
const { transform } = require('inflection');

var inflection = require( 'inflection' );

inflection.transform( 'all job', [ 'pluralize', 'capitalize', 'dasherize' ]); // === 'All-jobs'
transform('all job', [ 'pluralize', 'capitalize', 'dasherize' ]); // === 'All-jobs'
```

## Credit

Expand Down

0 comments on commit 9fb200b

Please sign in to comment.