|
| 1 | +/*! |
| 2 | + * inflection |
| 3 | + * Copyright(c) 2011 Ben Lin <ben@dreamerslab.com> |
| 4 | + * MIT Licensed |
| 5 | + * |
| 6 | + * @fileoverview |
| 7 | + * A port of inflection-js to node.js module. |
| 8 | + */ |
| 9 | +/** |
| 10 | + * This lets us detect if an Array contains a given element. |
| 11 | + * @param arr The subject array. |
| 12 | + * @param item Object to locate in the Array. |
| 13 | + * @param fromIndex Starts checking from this position in the Array.(optional) |
| 14 | + * @param compareFunc Function used to compare Array item vs passed item.(optional) |
| 15 | + * @returns Return index position in the Array of the passed item. |
| 16 | + * @example |
| 17 | + * |
| 18 | + * var inflection = require( 'inflection' ); |
| 19 | + * |
| 20 | + * inflection.indexOf([ 'hi','there' ], 'guys' ); // === -1 |
| 21 | + * inflection.indexOf([ 'hi','there' ], 'hi' ); // === 0 |
| 22 | + */ |
| 23 | +export declare function indexOf<T>(arr: T[], item: T, fromIndex?: number, compareFunc?: (el: T, arg1: T) => boolean): number; |
| 24 | +/** |
| 25 | + * This function adds pluralization support to every String object. |
| 26 | + * @param str The subject string. |
| 27 | + * @param plural Overrides normal output with said String.(optional) |
| 28 | + * @returns Singular English language nouns are returned in plural form. |
| 29 | + * @example |
| 30 | + * |
| 31 | + * var inflection = require( 'inflection' ); |
| 32 | + * |
| 33 | + * inflection.pluralize( 'person' ); // === 'people' |
| 34 | + * inflection.pluralize( 'octopus' ); // === 'octopuses' |
| 35 | + * inflection.pluralize( 'Hat' ); // === 'Hats' |
| 36 | + * inflection.pluralize( 'person', 'guys' ); // === 'guys' |
| 37 | + */ |
| 38 | +export declare function pluralize(str: string, plural?: string): string; |
| 39 | +/** |
| 40 | + * This function adds singularization support to every String object. |
| 41 | + * @param str The subject string. |
| 42 | + * @param singular Overrides normal output with said String.(optional) |
| 43 | + * @returns Plural English language nouns are returned in singular form. |
| 44 | + * @example |
| 45 | + * |
| 46 | + * var inflection = require( 'inflection' ); |
| 47 | + * |
| 48 | + * inflection.singularize( 'people' ); // === 'person' |
| 49 | + * inflection.singularize( 'octopuses' ); // === 'octopus' |
| 50 | + * inflection.singularize( 'Hats' ); // === 'Hat' |
| 51 | + * inflection.singularize( 'guys', 'person' ); // === 'person' |
| 52 | + */ |
| 53 | +export declare function singularize(str: string, singular?: string): string; |
| 54 | +/** |
| 55 | + * This function will pluralize or singularlize a String appropriately based on a number value |
| 56 | + * @param str The subject string. |
| 57 | + * @param count The number to base pluralization off of. |
| 58 | + * @param singular Overrides normal output with said String.(optional) |
| 59 | + * @param plural Overrides normal output with said String.(optional) |
| 60 | + * @returns English language nouns are returned in the plural or singular form based on the count. |
| 61 | + * @example |
| 62 | + * |
| 63 | + * var inflection = require( 'inflection' ); |
| 64 | + * |
| 65 | + * inflection.inflect( 'people' 1 ); // === 'person' |
| 66 | + * inflection.inflect( 'octopuses' 1 ); // === 'octopus' |
| 67 | + * inflection.inflect( 'Hats' 1 ); // === 'Hat' |
| 68 | + * inflection.inflect( 'guys', 1 , 'person' ); // === 'person' |
| 69 | + * inflection.inflect( 'inches', 1.5 ); // === 'inches' |
| 70 | + * inflection.inflect( 'person', 2 ); // === 'people' |
| 71 | + * inflection.inflect( 'octopus', 2 ); // === 'octopuses' |
| 72 | + * inflection.inflect( 'Hat', 2 ); // === 'Hats' |
| 73 | + * inflection.inflect( 'person', 2, null, 'guys' ); // === 'guys' |
| 74 | + */ |
| 75 | +export declare function inflect(str: string, count: number, singular?: string, plural?: string): string; |
| 76 | +/** |
| 77 | + * This function adds camelization support to every String object. |
| 78 | + * @param str The subject string. |
| 79 | + * @param lowFirstLetter Default is to capitalize the first letter of the results.(optional) |
| 80 | + * Passing true will lowercase it. |
| 81 | + * @returns Lower case underscored words will be returned in camel case. |
| 82 | + * additionally '/' is translated to '::' |
| 83 | + * @example |
| 84 | + * |
| 85 | + * var inflection = require( 'inflection' ); |
| 86 | + * |
| 87 | + * inflection.camelize( 'message_properties' ); // === 'MessageProperties' |
| 88 | + * inflection.camelize( 'message_properties', true ); // === 'messageProperties' |
| 89 | + */ |
| 90 | +export declare function camelize(str: string, lowFirstLetter?: boolean): string; |
| 91 | +/** |
| 92 | + * This function adds underscore support to every String object. |
| 93 | + * @param str The subject string. |
| 94 | + * @param allUpperCase Default is to lowercase and add underscore prefix.(optional) |
| 95 | + * Passing true will return as entered. |
| 96 | + * @returns Camel cased words are returned as lower cased and underscored. |
| 97 | + * additionally '::' is translated to '/'. |
| 98 | + * @example |
| 99 | + * |
| 100 | + * var inflection = require( 'inflection' ); |
| 101 | + * |
| 102 | + * inflection.underscore( 'MessageProperties' ); // === 'message_properties' |
| 103 | + * inflection.underscore( 'messageProperties' ); // === 'message_properties' |
| 104 | + * inflection.underscore( 'MP', true ); // === 'MP' |
| 105 | + */ |
| 106 | +export declare function underscore(str: string, allUpperCase?: boolean): string; |
| 107 | +/** |
| 108 | + * This function adds humanize support to every String object. |
| 109 | + * @param str The subject string. |
| 110 | + * @param lowFirstLetter Default is to capitalize the first letter of the results.(optional) |
| 111 | + * Passing true will lowercase it. |
| 112 | + * @returns Lower case underscored words will be returned in humanized form. |
| 113 | + * @example |
| 114 | + * |
| 115 | + * var inflection = require( 'inflection' ); |
| 116 | + * |
| 117 | + * inflection.humanize( 'message_properties' ); // === 'Message properties' |
| 118 | + * inflection.humanize( 'message_properties', true ); // === 'message properties' |
| 119 | + */ |
| 120 | +export declare function humanize(str: string, lowFirstLetter?: boolean): string; |
| 121 | +/** |
| 122 | + * This function adds capitalization support to every String object. |
| 123 | + * @param str The subject string. |
| 124 | + * @returns All characters will be lower case and the first will be upper. |
| 125 | + * @example |
| 126 | + * |
| 127 | + * var inflection = require( 'inflection' ); |
| 128 | + * |
| 129 | + * inflection.capitalize( 'message_properties' ); // === 'Message_properties' |
| 130 | + * inflection.capitalize( 'message properties', true ); // === 'Message properties' |
| 131 | + */ |
| 132 | +export declare function capitalize(str: string): string; |
| 133 | +/** |
| 134 | + * This function replaces underscores with dashes in the string. |
| 135 | + * @param str The subject string. |
| 136 | + * @returns Replaces all spaces or underscores with dashes. |
| 137 | + * @example |
| 138 | + * |
| 139 | + * var inflection = require( 'inflection' ); |
| 140 | + * |
| 141 | + * inflection.dasherize( 'message_properties' ); // === 'message-properties' |
| 142 | + * inflection.dasherize( 'Message Properties' ); // === 'Message-Properties' |
| 143 | + */ |
| 144 | +export declare function dasherize(str: string): string; |
| 145 | +/** |
| 146 | + * This function adds titleize support to every String object. |
| 147 | + * @param str The subject string. |
| 148 | + * @returns Capitalizes words as you would for a book title. |
| 149 | + * @example |
| 150 | + * |
| 151 | + * var inflection = require( 'inflection' ); |
| 152 | + * |
| 153 | + * inflection.titleize( 'message_properties' ); // === 'Message Properties' |
| 154 | + * inflection.titleize( 'message properties to keep' ); // === 'Message Properties to Keep' |
| 155 | + */ |
| 156 | +export declare function titleize(str: string): string; |
| 157 | +/** |
| 158 | + * This function adds demodulize support to every String object. |
| 159 | + * @param str The subject string. |
| 160 | + * @returns Removes module names leaving only class names.(Ruby style) |
| 161 | + * @example |
| 162 | + * |
| 163 | + * var inflection = require( 'inflection' ); |
| 164 | + * |
| 165 | + * inflection.demodulize( 'Message::Bus::Properties' ); // === 'Properties' |
| 166 | + */ |
| 167 | +export declare function demodulize(str: string): string; |
| 168 | +/** |
| 169 | + * This function adds tableize support to every String object. |
| 170 | + * @param str The subject string. |
| 171 | + * @returns Return camel cased words into their underscored plural form. |
| 172 | + * @example |
| 173 | + * |
| 174 | + * var inflection = require( 'inflection' ); |
| 175 | + * |
| 176 | + * inflection.tableize( 'MessageBusProperty' ); // === 'message_bus_properties' |
| 177 | + */ |
| 178 | +export declare function tableize(str: string): string; |
| 179 | +/** |
| 180 | + * This function adds classification support to every String object. |
| 181 | + * @param str The subject string. |
| 182 | + * @returns Underscored plural nouns become the camel cased singular form. |
| 183 | + * @example |
| 184 | + * |
| 185 | + * var inflection = require( 'inflection' ); |
| 186 | + * |
| 187 | + * inflection.classify( 'message_bus_properties' ); // === 'MessageBusProperty' |
| 188 | + */ |
| 189 | +export declare function classify(str: string): string; |
| 190 | +/** |
| 191 | + * This function adds foreign key support to every String object. |
| 192 | + * @param str The subject string. |
| 193 | + * @param dropIdUbar Default is to seperate id with an underbar at the end of the class name, |
| 194 | + you can pass true to skip it.(optional) |
| 195 | + * @returns Underscored plural nouns become the camel cased singular form. |
| 196 | + * @example |
| 197 | + * |
| 198 | + * var inflection = require( 'inflection' ); |
| 199 | + * |
| 200 | + * inflection.foreign_key( 'MessageBusProperty' ); // === 'message_bus_property_id' |
| 201 | + * inflection.foreign_key( 'MessageBusProperty', true ); // === 'message_bus_propertyid' |
| 202 | + */ |
| 203 | +export declare function foreignKey(str: string, dropIdUbar?: boolean): string; |
| 204 | +/** |
| 205 | + * This function adds ordinalize support to every String object. |
| 206 | + * @param str The subject string. |
| 207 | + * @returns Return all found numbers their sequence like '22nd'. |
| 208 | + * @example |
| 209 | + * |
| 210 | + * var inflection = require( 'inflection' ); |
| 211 | + * |
| 212 | + * inflection.ordinalize( 'the 1 pitch' ); // === 'the 1st pitch' |
| 213 | + */ |
| 214 | +export declare function ordinalize(str: string): string; |
| 215 | +declare const transformFunctions: { |
| 216 | + readonly pluralize: typeof pluralize; |
| 217 | + readonly singularize: typeof singularize; |
| 218 | + readonly camelize: typeof camelize; |
| 219 | + readonly underscore: typeof underscore; |
| 220 | + readonly humanize: typeof humanize; |
| 221 | + readonly capitalize: typeof capitalize; |
| 222 | + readonly dasherize: typeof dasherize; |
| 223 | + readonly titleize: typeof titleize; |
| 224 | + readonly demodulize: typeof demodulize; |
| 225 | + readonly tableize: typeof tableize; |
| 226 | + readonly classify: typeof classify; |
| 227 | + readonly foreignKey: typeof foreignKey; |
| 228 | + readonly ordinalize: typeof ordinalize; |
| 229 | +}; |
| 230 | +/** |
| 231 | + * This function performs multiple inflection methods on a string |
| 232 | + * @param str The subject string. |
| 233 | + * @param arr An array of inflection methods. |
| 234 | + * @returns |
| 235 | + * @example |
| 236 | + * |
| 237 | + * var inflection = require( 'inflection' ); |
| 238 | + * |
| 239 | + * inflection.transform( 'all job', [ 'pluralize', 'capitalize', 'dasherize' ]); // === 'All-jobs' |
| 240 | + */ |
| 241 | +export declare function transform(str: string, arr: (keyof typeof transformFunctions)[]): string; |
| 242 | +export {}; |
0 commit comments