Hello, I’m Joshua (public account). Enthusiastic to do open source, write articles. Objective To help college students, just entering the workplace partners can build their own front-end learning system as soon as possible. If you are confused about your study, please follow me and find me to communicate. I will reply you in real time.

I (full name: inflect)

Installation:

npm install i
Copy the code

Use:

Before use, first import package I:

var inflect = require('i')();
Copy the code

Pass true on startup:

var inflect = require('i')(true);
Copy the code

All of the following API functions can be called directly on strings:

inflect.titleize('messages to store') // === 'Messages To Store'

'messages to store'.titleize // === 'Messages To Store'
Copy the code

Pluralize: in the plural

inflect.pluralize('person'); // === 'people'
inflect.pluralize('octopus'); // === 'octopi'
inflect.pluralize('Hat'); // === 'Hats'
Copy the code

Singularize: singular

inflect.singularize('people'); // === 'person'
inflect.singularize('octopi'); // === 'octopus'
inflect.singularize('Hats'); // === 'Hat'
Copy the code

Camelize: indicates the name of a camel

  • The first argument: string
  • Second parameter: whether the big hump naming rule has been displayed
inflect.camelize('message_properties'); // === 'MessageProperties'
inflect.camelize('message_properties', false); // === 'messageProperties'
Copy the code

Naming rules for small humps: Lowercase for the first word, uppercase for all other words

Write it as myFirstName

Big hump naming rules: capitalize the first word and all other words

Write it as MyFirstName

Underscore: underscore

inflect.underscore('MessageProperties'); // === 'message_properties'
inflect.underscore('messageProperties'); // === 'message_properties'
Copy the code

Humanize: display in a more humanized form

Understanding: is to make the form of expression more in line with ordinary people, ordinary people’s understanding

inflect.humanize('message_id'); // === 'Message'
Copy the code

Dasherize: Sprint (hard to translate)

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

Copy the code

Titleize: In the form of a title

inflect.titleize('message_properties'); // === 'Message Properties'
inflect.titleize('message properties to keep'); // === 'Message Properties to Keep'
Copy the code

Demodulize: demodulation

Gets the last property accessed in the string ‘message.bus. Properties’

inflect.demodulize('Message.Bus.Properties'); // === 'Properties'

Copy the code

Tableize: Represented as a table

inflect.tableize('MessageBusProperty'); // === 'message_bus_properties'

Copy the code

The Classify: classification

inflect.classify('message_bus_properties'); // === 'MessageBusProperty'
Copy the code

Foreign key: indicates a Foreign key

inflect.foreign_key('MessageBusProperty'); // === 'message_bus_property_id'
inflect.foreign_key('MessageBusProperty', false); // === 'message_bus_propertyid'
Copy the code

Ordinalize: expressed in order

inflect.ordinalize( '1' ); // === '1st'
Copy the code

Custom change rules

Custom plural: Custom plural

We can use regular expressions in any of these custom rules:

inflect.inflections.plural('person', 'guys');
inflect.pluralize('person'); // === 'guys'
inflect.singularize('guys'); // === 'guy'
Copy the code

Custom singular: Custom singular

inflect.inflections.irregular('person', 'guys')
inflect.pluralize('person'); // === 'guys'
inflect.singularize('guys'); // === 'person'
Copy the code

Custom Human: Custom human

Understanding: is to make the form of expression more in line with ordinary people, ordinary people’s understanding

inflect.inflections.human(/^(.*)_cnt$/i, '$1_count');
inflect.inflections.humanize('jargon_cnt'); // === 'Jargon count'
Copy the code

Custom uncountable: user-defined uncountable words

inflect.inflections.uncountable('oil')
inflect.pluralize('oil'); // === 'oil'
inflect.singularize('oil'); // === 'oil'
Copy the code