inflection

  • Version 3.0.0
  • Published
  • 90.4 kB
  • No dependencies
  • MIT license

Install

npm i inflection
yarn add inflection
pnpm add inflection

Overview

A port of inflection-js to node.js module

Index

Variables

variable transformFunctions

const transformFunctions: {
readonly pluralize: typeof pluralize;
readonly singularize: typeof singularize;
readonly camelize: typeof camelize;
readonly underscore: typeof underscore;
readonly humanize: typeof humanize;
readonly capitalize: typeof capitalize;
readonly dasherize: typeof dasherize;
readonly titleize: typeof titleize;
readonly demodulize: typeof demodulize;
readonly tableize: typeof tableize;
readonly classify: typeof classify;
readonly foreignKey: typeof foreignKey;
readonly ordinalize: typeof ordinalize;
};

    Functions

    function camelize

    camelize: (str: string, lowFirstLetter?: boolean) => string;
    • This function adds camelization support to every String object.

      Parameter str

      The subject string.

      Parameter lowFirstLetter

      Default is to capitalize the first letter of the results.(optional) Passing true will lowercase it.

      Returns

      Lower case underscored words will be returned in camel case. additionally '/' is translated to '::'

      Example 1

      const inflection = require( 'inflection' );

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

    function capitalize

    capitalize: (str: string) => string;
    • This function adds capitalization support to every String object.

      Parameter str

      The subject string.

      Returns

      All characters will be lower case and the first will be upper.

      Example 1

      const inflection = require( 'inflection' );

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

    function classify

    classify: (str: string) => string;
    • This function adds classification support to every String object.

      Parameter str

      The subject string.

      Returns

      Underscored plural nouns become the camel cased singular form.

      Example 1

      const inflection = require( 'inflection' );

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

    function dasherize

    dasherize: (str: string) => string;
    • This function replaces underscores with dashes in the string.

      Parameter str

      The subject string.

      Returns

      Replaces all spaces or underscores with dashes.

      Example 1

      const inflection = require( 'inflection' );

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

    function demodulize

    demodulize: (str: string) => string;
    • This function adds demodulize support to every String object.

      Parameter str

      The subject string.

      Returns

      Removes module names leaving only class names.(Ruby style)

      Example 1

      const inflection = require( 'inflection' );

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

    function foreignKey

    foreignKey: (str: string, dropIdUbar?: boolean) => string;
    • This function adds foreign key support to every String object.

      Parameter str

      The subject string.

      Parameter dropIdUbar

      Default is to seperate id with an underbar at the end of the class name, you can pass true to skip it.(optional)

      Returns

      Underscored plural nouns become the camel cased singular form.

      Example 1

      const inflection = require( 'inflection' );

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

    function humanize

    humanize: (str: string, lowFirstLetter?: boolean) => string;
    • This function adds humanize support to every String object.

      Parameter str

      The subject string.

      Parameter lowFirstLetter

      Default is to capitalize the first letter of the results.(optional) Passing true will lowercase it.

      Returns

      Lower case underscored words will be returned in humanized form.

      Example 1

      const inflection = require( 'inflection' );

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

    function inflect

    inflect: (
    str: string,
    count: number,
    singular?: string,
    plural?: string
    ) => string;
    • This function will pluralize or singularlize a String appropriately based on a number value

      Parameter str

      The subject string.

      Parameter count

      The number to base pluralization off of.

      Parameter singular

      Overrides normal output with said String.(optional)

      Parameter plural

      Overrides normal output with said String.(optional)

      Returns

      English language nouns are returned in the plural or singular form based on the count.

      Example 1

      const inflection = require( 'inflection' );

      inflection.inflect( 'people' 1 ); // === 'person' inflection.inflect( 'octopuses' 1 ); // === 'octopus' inflection.inflect( 'Hats' 1 ); // === 'Hat' inflection.inflect( 'guys', 1 , 'person' ); // === 'person' inflection.inflect( 'inches', 1.5 ); // === 'inches' inflection.inflect( 'person', 2 ); // === 'people' inflection.inflect( 'octopus', 2 ); // === 'octopuses' inflection.inflect( 'Hat', 2 ); // === 'Hats' inflection.inflect( 'person', 2, null, 'guys' ); // === 'guys'

    function ordinalize

    ordinalize: (str: string) => string;
    • This function adds ordinalize support to every String object.

      Parameter str

      The subject string.

      Returns

      Return all found numbers their sequence like '22nd'.

      Example 1

      const inflection = require( 'inflection' );

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

    function pluralize

    pluralize: (str: string, plural?: string) => string;
    • This function adds pluralization support to every String object.

      Parameter str

      The subject string.

      Parameter plural

      Overrides normal output with said String.(optional)

      Returns

      Singular English language nouns are returned in plural form.

      Example 1

      const inflection = require( 'inflection' );

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

    function singularize

    singularize: (str: string, singular?: string) => string;
    • This function adds singularization support to every String object.

      Parameter str

      The subject string.

      Parameter singular

      Overrides normal output with said String.(optional)

      Returns

      Plural English language nouns are returned in singular form.

      Example 1

      const inflection = require( 'inflection' );

      inflection.singularize( 'people' ); // === 'person' inflection.singularize( 'octopuses' ); // === 'octopus' inflection.singularize( 'Hats' ); // === 'Hat' inflection.singularize( 'guys', 'person' ); // === 'person'

    function tableize

    tableize: (str: string) => string;
    • This function adds tableize support to every String object.

      Parameter str

      The subject string.

      Returns

      Return camel cased words into their underscored plural form.

      Example 1

      const inflection = require( 'inflection' );

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

    function titleize

    titleize: (str: string) => string;
    • This function adds titleize support to every String object.

      Parameter str

      The subject string.

      Returns

      Capitalizes words as you would for a book title.

      Example 1

      const inflection = require( 'inflection' );

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

    function transform

    transform: (str: string, arr: (keyof typeof transformFunctions)[]) => string;
    • This function performs multiple inflection methods on a string

      Parameter str

      The subject string.

      Parameter arr

      An array of inflection methods.

      Returns

      Example 1

      const inflection = require( 'inflection' );

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

    function underscore

    underscore: (str: string, allUpperCase?: boolean) => string;
    • This function adds underscore support to every String object.

      Parameter str

      The subject string.

      Parameter allUpperCase

      Default is to lowercase and add underscore prefix.(optional) Passing true will return as entered.

      Returns

      Camel cased words are returned as lower cased and underscored. additionally '::' is translated to '/'.

      Example 1

      const inflection = require( 'inflection' );

      inflection.underscore( 'MessageProperties' ); // === 'message_properties' inflection.underscore( 'messageProperties' ); // === 'message_properties' inflection.underscore( 'MP', true ); // === 'MP'

    Package Files (1)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (2)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/inflection.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/inflection)
    • HTML
      <a href="https://www.jsdocs.io/package/inflection"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>