0.3.7 • Published 3 years ago

i v0.3.7

Weekly downloads
701,429
License
-
Repository
github
Last release
3 years ago

inflect

customizable inflections for nodejs

NOTE: 0.3.2 was accidentally unpublished from the server and npm doesn't allow me to publish it back. Please upgrade to 0.3.3

Installation

npm install i

Usage

Require the module before using

var inflect = require('i')();

All the below api functions can be called directly on a string

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

only if true is passed while initiating

var inflect = require('i')(true);

Pluralize

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

Singularize

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

Camelize

inflect.camelize('message_properties'); // === 'MessageProperties'
inflect.camelize('message_properties', false); // === 'messageProperties'

Underscore

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

Humanize

inflect.humanize('message_id'); // === 'Message'

Dasherize

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

Titleize

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

Demodulize

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

Tableize

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

Classify

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

Foreign key

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

Ordinalize

inflect.ordinalize( '1' ); // === '1st'

Custom rules for inflection

Custom plural

We can use regexp in any of these custom rules

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

Custom singular

inflect.inflections.singular('guys', 'person')
inflect.singularize('guys'); // === 'person'
inflect.pluralize('person'); // === 'people'

Custom irregular

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

Custom human

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

Custom uncountable

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

Contributors

Here is a list of Contributors

TODO

  • More obscure test cases

I accept pull requests and guarantee a reply back within a day

License

MIT/X11

Bug Reports

Report here. Guaranteed reply within a day.

Contact

Pavan Kumar Sunkara (pavan.sss1991@gmail.com)

Follow me on github, twitter

eog_seog_xx@jeje-devs/ts-rollercodeinsightsui@avocad0/sdkuni-codeeeunicodeeui-component-bright-labwebintensivebyevolutionminibig-js-module@mubeen_ahmed/epubjs-rn@seongjoojin/epubjs-rnevaluation-engine@tkil/tmpl-cliyellowcard-bitcoin-apigenerate-tempx@gocelestial/indieauthcube-mainvulcan-cra-startermylib2-test-imgspa-central-stylesspa-central-styles-freechattingapp@autovance/customer-translatordoggo-corebitiddigitalmatterslibraryqxz-mobileelectron-native-patch-loaderpanacloud-shariq-managerunova-asset-apiprome@skoda-dms/component-libnpm-bot-discord-freeunova-middleware-smartcontract-blockchainget-utm-paramsvue-taranslation-guangvue-taranslation-huaivue-taranslation-huangvue-taranslation-mrhvue-taranslation-mrhuaivue-taranslation-zhunitauros-material-libowgrapesjspowerpuffmechmaniadp-sellerswen-languagespc-rulesengine-sjpc-rulesengine-spnode-roomwitty-email-package@chn-js/canvas-toolskwil-js-sdkpang-utils@reframework/components-v1faccos-react-componentsantd-demo-tss-dada-sgenerator-schlesinger@xqy/keystone@infinitebrahmanuniverse/nolb-i@thequack/sharedoute-ds-tabsoute-ds-accordianoute-ds-action-cardoute-ds-carouseloute-ds-file-pickeroute-ds-file-preview-cardoute-ds-folder-cardoute-ds-folder-card-groupoute-ds-iconsoute-ds-image-boardoute-ds-image-cardoute-ds-info-boardoute-ds-inline-editingoute-ds-list-cardoute-ds-modaloute-ds-nav-baroute-ds-radio-buttonoute-ds-search-baroute-ds-select-inputoute-ds-simple-inputoute-ds-slideroute-ds-stat-tileoute-ds-toolboxoute-ds-steppereva-plugin-physics2dmrkreszsolid-uiapple-music-jwt-generatorrect-components-007@everything-registry/sub-chunk-1886react-components-007aig1919akellotest-yklead-gen-domoas2schema.orgopus-authopenmrs-react-scripts-example
0.3.7

3 years ago

0.3.6

7 years ago

0.3.5

8 years ago

0.3.4

8 years ago

0.3.3

9 years ago

0.3.2

11 years ago

0.3.1

12 years ago

0.3.0

12 years ago

0.2.0

12 years ago