forked from andrewplummer/Sugar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinflections.js
552 lines (507 loc) · 20.4 KB
/
inflections.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
'use strict';
/***
*
* @package Inflections
* @dependency string
* @description Pluralization similar to ActiveSupport including uncountable words and acronyms. Humanized and URL-friendly strings.
*
***/
/***
* @namespace String
*
***/
var plurals = [],
singulars = [],
uncountables = [],
humans = [],
acronyms = {},
Downcased,
Inflector,
NormalizeMap = {},
NormalizeReg,
NormalizeSource;
function removeFromArray(arr, find) {
var index = arr.indexOf(find);
if (index > -1) {
arr.splice(index, 1);
}
}
function removeFromUncountablesAndAddTo(arr, rule, replacement) {
if (isString(rule)) {
removeFromArray(uncountables, rule);
}
removeFromArray(uncountables, replacement);
arr.unshift({ rule: rule, replacement: replacement })
}
function paramMatchesType(param, type) {
return param == type || param == 'all' || !param;
}
function isUncountable(word) {
return uncountables.some(function(uncountable) {
return new regexp('\\b' + uncountable + '$', 'i').test(word);
});
}
function inflect(word, pluralize) {
word = isString(word) ? word.toString() : '';
if (isBlank(word) || isUncountable(word)) {
return word;
} else {
return runReplacements(word, pluralize ? plurals : singulars);
}
}
function runReplacements(word, table) {
iterateOverObject(table, function(i, inflection) {
if (word.match(inflection.rule)) {
word = word.replace(inflection.rule, inflection.replacement);
return false;
}
});
return word;
}
function capitalizeWithoutDowncasing(word) {
return word.replace(/^\W*[a-z]/, function(w){
return w.toUpperCase();
});
}
function humanize(str) {
var str = runReplacements(str, humans), acronym;
str = str.replace(/_id$/g, '');
str = str.replace(/(_)?([a-z\d]*)/gi, function(match, _, word){
var lower = word.toLowerCase();
acronym = hasOwnProperty(acronyms, lower) ? acronyms[lower] : null;
return (_ ? ' ' : '') + (acronym || lower);
});
return capitalizeWithoutDowncasing(str);
}
function toAscii(str) {
return str.replace(NormalizeReg, function(character) {
return NormalizeMap[character];
});
}
function buildNormalizeMap() {
var normalized, str, all = '';
for(normalized in NormalizeSource) {
if (!NormalizeSource.hasOwnProperty(normalized)) continue;
str = NormalizeSource[normalized];
str.split('').forEach(function(character) {
NormalizeMap[character] = normalized;
});
all += str;
}
NormalizeReg = RegExp('[' + all + ']', 'g');
}
Inflector = {
/*
* Specifies a new acronym. An acronym must be specified as it will appear in a camelized string. An underscore
* string that contains the acronym will retain the acronym when passed to %camelize%, %humanize%, or %titleize%.
* A camelized string that contains the acronym will maintain the acronym when titleized or humanized, and will
* convert the acronym into a non-delimited single lowercase word when passed to String#underscore.
*
* Examples:
* String.Inflector.acronym('HTML')
* 'html'.titleize() -> 'HTML'
* 'html'.camelize() -> 'HTML'
* 'MyHTML'.underscore() -> 'my_html'
*
* The acronym, however, must occur as a delimited unit and not be part of another word for conversions to recognize it:
*
* String.Inflector.acronym('HTTP')
* 'my_http_delimited'.camelize() -> 'MyHTTPDelimited'
* 'https'.camelize() -> 'Https', not 'HTTPs'
* 'HTTPS'.underscore() -> 'http_s', not 'https'
*
* String.Inflector.acronym('HTTPS')
* 'https'.camelize() -> 'HTTPS'
* 'HTTPS'.underscore() -> 'https'
*
* Note: Acronyms that are passed to %pluralize% will no longer be recognized, since the acronym will not occur as
* a delimited unit in the pluralized result. To work around this, you must specify the pluralized form as an
* acronym as well:
*
* String.Inflector.acronym('API')
* 'api'.pluralize().camelize() -> 'Apis'
*
* String.Inflector.acronym('APIs')
* 'api'.pluralize().camelize() -> 'APIs'
*
* %acronym% may be used to specify any word that contains an acronym or otherwise needs to maintain a non-standard
* capitalization. The only restriction is that the word must begin with a capital letter.
*
* Examples:
* String.Inflector.acronym('RESTful')
* 'RESTful'.underscore() -> 'restful'
* 'RESTfulController'.underscore() -> 'restful_controller'
* 'RESTfulController'.titleize() -> 'RESTful Controller'
* 'restful'.camelize() -> 'RESTful'
* 'restful_controller'.camelize() -> 'RESTfulController'
*
* String.Inflector.acronym('McDonald')
* 'McDonald'.underscore() -> 'mcdonald'
* 'mcdonald'.camelize() -> 'McDonald'
*/
'acronym': function(word) {
acronyms[word.toLowerCase()] = word;
var all = object.keys(acronyms).map(function(key) {
return acronyms[key];
});
Inflector.acronymRegExp = regexp(all.join('|'), 'g');
},
/*
* Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
* The replacement should always be a string that may include references to the matched data from the rule.
*/
'plural': function(rule, replacement) {
removeFromUncountablesAndAddTo(plurals, rule, replacement);
},
/*
* Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
* The replacement should always be a string that may include references to the matched data from the rule.
*/
'singular': function(rule, replacement) {
removeFromUncountablesAndAddTo(singulars, rule, replacement);
},
/*
* Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
* for strings, not regular expressions. You simply pass the irregular in singular and plural form.
*
* Examples:
* String.Inflector.irregular('octopus', 'octopi')
* String.Inflector.irregular('person', 'people')
*/
'irregular': function(singular, plural) {
var singularFirst = stringFirst(singular),
singularRest = stringFrom(singular, 1),
pluralFirst = stringFirst(plural),
pluralRest = stringFrom(plural, 1),
pluralFirstUpper = pluralFirst.toUpperCase(),
pluralFirstLower = pluralFirst.toLowerCase(),
singularFirstUpper = singularFirst.toUpperCase(),
singularFirstLower = singularFirst.toLowerCase();
removeFromArray(uncountables, singular);
removeFromArray(uncountables, plural);
if (singularFirstUpper == pluralFirstUpper) {
Inflector.plural(new regexp(stringAssign('({1}){2}$', [singularFirst, singularRest]), 'i'), '$1' + pluralRest);
Inflector.plural(new regexp(stringAssign('({1}){2}$', [pluralFirst, pluralRest]), 'i'), '$1' + pluralRest);
Inflector.singular(new regexp(stringAssign('({1}){2}$', [pluralFirst, pluralRest]), 'i'), '$1' + singularRest);
} else {
Inflector.plural(new regexp(stringAssign('{1}{2}$', [singularFirstUpper, singularRest])), pluralFirstUpper + pluralRest);
Inflector.plural(new regexp(stringAssign('{1}{2}$', [singularFirstLower, singularRest])), pluralFirstLower + pluralRest);
Inflector.plural(new regexp(stringAssign('{1}{2}$', [pluralFirstUpper, pluralRest])), pluralFirstUpper + pluralRest);
Inflector.plural(new regexp(stringAssign('{1}{2}$', [pluralFirstLower, pluralRest])), pluralFirstLower + pluralRest);
Inflector.singular(new regexp(stringAssign('{1}{2}$', [pluralFirstUpper, pluralRest])), singularFirstUpper + singularRest);
Inflector.singular(new regexp(stringAssign('{1}{2}$', [pluralFirstLower, pluralRest])), singularFirstLower + singularRest);
}
},
/*
* Add uncountable words that shouldn't be attempted inflected.
*
* Examples:
* String.Inflector.uncountable('money')
* String.Inflector.uncountable('money', 'information')
* String.Inflector.uncountable(['money', 'information', 'rice'])
*/
'uncountable': function(first) {
var add;
if (array.isArray(first)) {
add = first;
} else {
// Optimized: no leaking arguments
var args = [], $i; for($i = 0; $i < arguments.length; $i++) args.push(arguments[$i]);
add = args;
}
uncountables = uncountables.concat(add);
},
/*
* Specifies a humanized form of a string by a regular expression rule or by a string mapping.
* When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
* When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name')
*
* Examples:
* String.Inflector.human(/_cnt$/i, '_count')
* String.Inflector.human('legacy_col_person_name', 'Name')
*/
'human': function(rule, replacement) {
humans.unshift({ rule: rule, replacement: replacement })
},
/*
* Clears the loaded inflections within a given scope (default is 'all').
* Options are: 'all', 'plurals', 'singulars', 'uncountables', 'humans'.
*
* Examples:
* String.Inflector.clear('all')
* String.Inflector.clear('plurals')
*/
'clear': function(type) {
if (paramMatchesType(type, 'singulars')) singulars = [];
if (paramMatchesType(type, 'plurals')) plurals = [];
if (paramMatchesType(type, 'uncountables')) uncountables = [];
if (paramMatchesType(type, 'humans')) humans = [];
if (paramMatchesType(type, 'acronyms')) acronyms = {};
}
};
Downcased = [
'and', 'or', 'nor', 'a', 'an', 'the', 'so', 'but', 'to', 'of', 'at',
'by', 'from', 'into', 'on', 'onto', 'off', 'out', 'in', 'over',
'with', 'for'
];
Inflector.plural(/$/, 's');
Inflector.plural(/s$/gi, 's');
Inflector.plural(/(ax|test)is$/gi, '$1es');
Inflector.plural(/(octop|fung|foc|radi|alumn|cact)(i|us)$/gi, '$1i');
Inflector.plural(/(census|alias|status|fetus|genius|virus)$/gi, '$1es');
Inflector.plural(/(bu)s$/gi, '$1ses');
Inflector.plural(/(buffal|tomat)o$/gi, '$1oes');
Inflector.plural(/([ti])um$/gi, '$1a');
Inflector.plural(/([ti])a$/gi, '$1a');
Inflector.plural(/sis$/gi, 'ses');
Inflector.plural(/f+e?$/gi, 'ves');
Inflector.plural(/(cuff|roof)$/gi, '$1s');
Inflector.plural(/([ht]ive)$/gi, '$1s');
Inflector.plural(/([^aeiouy]o)$/gi, '$1es');
Inflector.plural(/([^aeiouy]|qu)y$/gi, '$1ies');
Inflector.plural(/(x|ch|ss|sh)$/gi, '$1es');
Inflector.plural(/(tr|vert)(?:ix|ex)$/gi, '$1ices');
Inflector.plural(/([ml])ouse$/gi, '$1ice');
Inflector.plural(/([ml])ice$/gi, '$1ice');
Inflector.plural(/^(ox)$/gi, '$1en');
Inflector.plural(/^(oxen)$/gi, '$1');
Inflector.plural(/(quiz)$/gi, '$1zes');
Inflector.plural(/(phot|cant|hom|zer|pian|portic|pr|quart|kimon)o$/gi, '$1os');
Inflector.plural(/(craft)$/gi, '$1');
Inflector.plural(/([ft])[eo]{2}(th?)$/gi, '$1ee$2');
Inflector.singular(/s$/gi, '');
Inflector.singular(/([pst][aiu]s)$/gi, '$1');
Inflector.singular(/([aeiouy])ss$/gi, '$1ss');
Inflector.singular(/(n)ews$/gi, '$1ews');
Inflector.singular(/([ti])a$/gi, '$1um');
Inflector.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/gi, '$1$2sis');
Inflector.singular(/(^analy)ses$/gi, '$1sis');
Inflector.singular(/(i)(f|ves)$/i, '$1fe');
Inflector.singular(/([aeolr]f?)(f|ves)$/i, '$1f');
Inflector.singular(/([ht]ive)s$/gi, '$1');
Inflector.singular(/([^aeiouy]|qu)ies$/gi, '$1y');
Inflector.singular(/(s)eries$/gi, '$1eries');
Inflector.singular(/(m)ovies$/gi, '$1ovie');
Inflector.singular(/(x|ch|ss|sh)es$/gi, '$1');
Inflector.singular(/([ml])(ous|ic)e$/gi, '$1ouse');
Inflector.singular(/(bus)(es)?$/gi, '$1');
Inflector.singular(/(o)es$/gi, '$1');
Inflector.singular(/(shoe)s?$/gi, '$1');
Inflector.singular(/(cris|ax|test)[ie]s$/gi, '$1is');
Inflector.singular(/(octop|fung|foc|radi|alumn|cact)(i|us)$/gi, '$1us');
Inflector.singular(/(census|alias|status|fetus|genius|virus)(es)?$/gi, '$1');
Inflector.singular(/^(ox)(en)?/gi, '$1');
Inflector.singular(/(vert)(ex|ices)$/gi, '$1ex');
Inflector.singular(/tr(ix|ices)$/gi, 'trix');
Inflector.singular(/(quiz)(zes)?$/gi, '$1');
Inflector.singular(/(database)s?$/gi, '$1');
Inflector.singular(/ee(th?)$/gi, 'oo$1');
Inflector.irregular('person', 'people');
Inflector.irregular('man', 'men');
Inflector.irregular('deer', 'deer');
Inflector.irregular('human', 'humans');
Inflector.irregular('child', 'children');
Inflector.irregular('sex', 'sexes');
Inflector.irregular('move', 'moves');
Inflector.irregular('save', 'saves');
Inflector.irregular('goose', 'geese');
Inflector.irregular('zombie', 'zombies');
Inflector.uncountable('equipment,information,rice,money,species,series,fish,sheep,jeans'.split(','));
NormalizeSource = {
'A': 'AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ',
'B': 'BⒷBḂḄḆɃƂƁ',
'C': 'CⒸCĆĈĊČÇḈƇȻꜾ',
'D': 'DⒹDḊĎḌḐḒḎĐƋƊƉꝹ',
'E': 'EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ',
'F': 'FⒻFḞƑꝻ',
'G': 'GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ',
'H': 'HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ',
'I': 'IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ',
'J': 'JⒿJĴɈ',
'K': 'KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ',
'L': 'LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ',
'M': 'MⓂMḾṀṂⱮƜ',
'N': 'NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ',
'O': 'OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ',
'P': 'PⓅPṔṖƤⱣꝐꝒꝔ',
'Q': 'QⓆQꝖꝘɊ',
'R': 'RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ',
'S': 'SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ',
'T': 'TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ',
'U': 'UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ',
'V': 'VⓋVṼṾƲꝞɅ',
'W': 'WⓌWẀẂŴẆẄẈⱲ',
'X': 'XⓍXẊẌ',
'Y': 'YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ',
'Z': 'ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ',
'a': 'aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐ',
'b': 'bⓑbḃḅḇƀƃɓ',
'c': 'cⓒcćĉċčçḉƈȼꜿↄ',
'd': 'dⓓdḋďḍḑḓḏđƌɖɗꝺ',
'e': 'eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ',
'f': 'fⓕfḟƒꝼ',
'g': 'gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ',
'h': 'hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ',
'i': 'iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı',
'j': 'jⓙjĵǰɉ',
'k': 'kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ',
'l': 'lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ',
'm': 'mⓜmḿṁṃɱɯ',
'n': 'nⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥ',
'o': 'oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ',
'p': 'pⓟpṕṗƥᵽꝑꝓꝕ',
'q': 'qⓠqɋꝗꝙ',
'r': 'rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ',
's': 'sⓢsśṥŝṡšṧṣṩșşȿꞩꞅẛ',
't': 'tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ',
'u': 'uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ',
'v': 'vⓥvṽṿʋꝟʌ',
'w': 'wⓦwẁẃŵẇẅẘẉⱳ',
'x': 'xⓧxẋẍ',
'y': 'yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ',
'z': 'zⓩzźẑżžẓẕƶȥɀⱬꝣ',
'AA': 'Ꜳ',
'AE': 'ÆǼǢ',
'AO': 'Ꜵ',
'AU': 'Ꜷ',
'AV': 'ꜸꜺ',
'AY': 'Ꜽ',
'DZ': 'DZDŽ',
'Dz': 'DzDž',
'LJ': 'LJ',
'Lj': 'Lj',
'NJ': 'NJ',
'Nj': 'Nj',
'OI': 'Ƣ',
'OO': 'Ꝏ',
'OU': 'Ȣ',
'TZ': 'Ꜩ',
'VY': 'Ꝡ',
'aa': 'ꜳ',
'ae': 'æǽǣ',
'ao': 'ꜵ',
'au': 'ꜷ',
'av': 'ꜹꜻ',
'ay': 'ꜽ',
'dz': 'dzdž',
'hv': 'ƕ',
'lj': 'lj',
'nj': 'nj',
'oi': 'ƣ',
'ou': 'ȣ',
'oo': 'ꝏ',
'ss': 'ß',
'tz': 'ꜩ',
'vy': 'ꝡ'
};
extend(string, {
/***
* @method pluralize()
* @returns String
* @short Returns the plural form of the word in the string.
* @example
*
* 'post'.pluralize() -> 'posts'
* 'octopus'.pluralize() -> 'octopi'
* 'sheep'.pluralize() -> 'sheep'
* 'words'.pluralize() -> 'words'
* 'CamelOctopus'.pluralize() -> 'CamelOctopi'
*
***/
'pluralize': function() {
return inflect(this, true);
},
/***
* @method singularize()
* @returns String
* @short The reverse of String#pluralize. Returns the singular form of a word in a string.
* @example
*
* 'posts'.singularize() -> 'post'
* 'octopi'.singularize() -> 'octopus'
* 'sheep'.singularize() -> 'sheep'
* 'word'.singularize() -> 'word'
* 'CamelOctopi'.singularize() -> 'CamelOctopus'
*
***/
'singularize': function() {
return inflect(this, false);
},
/***
* @method humanize()
* @returns String
* @short Creates a human readable string.
* @extra Capitalizes the first word and turns underscores into spaces and strips a trailing '_id', if any. Like String#titleize, this is meant for creating pretty output.
* @example
*
* 'employee_salary'.humanize() -> 'Employee salary'
* 'author_id'.humanize() -> 'Author'
*
***/
'humanize': function() {
return humanize(this);
},
/***
* @method titleize()
* @returns String
* @short Creates a title version of the string.
* @extra Capitalizes all the words and replaces some characters in the string to create a nicer looking title. String#titleize is meant for creating pretty output.
* @example
*
* 'man from the boondocks'.titleize() -> 'Man from the Boondocks'
* 'x-men: the last stand'.titleize() -> 'X Men: The Last Stand'
* 'TheManWithoutAPast'.titleize() -> 'The Man Without a Past'
* 'raiders_of_the_lost_ark'.titleize() -> 'Raiders of the Lost Ark'
*
***/
'titleize': function() {
var fullStopPunctuation = /[.:;!]$/, hasPunctuation, lastHadPunctuation, isFirstOrLast;
var str = humanize(spacify(this));
return eachWord(str, function(word, index, words) {
hasPunctuation = fullStopPunctuation.test(word);
isFirstOrLast = index == 0 || index == words.length - 1 || hasPunctuation || lastHadPunctuation;
lastHadPunctuation = hasPunctuation;
if (isFirstOrLast || Downcased.indexOf(word) === -1) {
return capitalizeWithoutDowncasing(word, true);
} else {
return word;
}
}).join(' ');
},
/***
* @method parameterize()
* @returns String
* @short Replaces special characters in a string so that it may be used as part of a pretty URL.
* @example
*
* 'hell, no!'.parameterize() -> 'hell-no'
*
***/
'parameterize': function(separator) {
var str = toAscii(this);
if (separator === undefined) separator = '-';
str = str.replace(/[^a-z0-9\-_]+/gi, separator)
if (separator) {
str = str.replace(new regexp(stringAssign('^{sep}+|{sep}+$|({sep}){sep}+', [{ 'sep': escapeRegExp(separator) }]), 'g'), '$1');
}
return encodeURI(str.toLowerCase());
},
/***
* @method toAscii()
* @returns String
* @short Returns the string with accented and non-standard Latin-based characters converted into ASCII approximate equivalents.
* @example
*
* 'á'.toAscii() -> 'a'
* 'Ménage à trois'.toAscii() -> 'Menage a trois'
* 'Volkswagen'.toAscii() -> 'Volkswagen'
* 'FULLWIDTH'.toAscii() -> 'FULLWIDTH'
*
***/
'toAscii': function() {
return toAscii(this);
}
});
sugarString.Inflector = Inflector;
sugarString.Inflector.acronyms = acronyms;
buildNormalizeMap();