1
1
/*!
2
- * Voca string library 1.1 .0
2
+ * Voca string library 1.2 .0
3
3
* https://vocajs.com
4
4
*
5
5
* Copyright Dmitri Pavlutin and other contributors
@@ -518,7 +518,7 @@ function camelCase(subject) {
518
518
function decapitalize ( subject ) {
519
519
var subjectString = coerceToString ( subject ) ;
520
520
if ( subjectString === '' ) {
521
- return subjectString ;
521
+ return '' ;
522
522
}
523
523
return subjectString . substr ( 0 , 1 ) . toLowerCase ( ) + subjectString . substr ( 1 ) ;
524
524
}
@@ -596,6 +596,33 @@ function upperCase(subject) {
596
596
return subjectString . toUpperCase ( ) ;
597
597
}
598
598
599
+ /**
600
+ * Converts the subject to title case.
601
+ *
602
+ * @function titleCase
603
+ * @static
604
+ * @since 1.2.0
605
+ * @memberOf Case
606
+ * @param {string } [subject=''] The string to convert to title case.
607
+ * @param {Array } [ignoreWords] The words that should not be capitalized.
608
+ * @return {string } Returns the title case string.
609
+ * @example
610
+ * v.titleCase('learning to fly');
611
+ * // => 'Learning To Fly'
612
+ *
613
+ * v.titleCase('another brick in the wall', ['in', 'the']);
614
+ * // => 'Another Brick in the Wall'
615
+ */
616
+ function titleCase ( subject , ignoreWords ) {
617
+ var subjectString = coerceToString ( subject ) ;
618
+ var ignoreWordsArray = Array . isArray ( ignoreWords ) ? ignoreWords : [ ] ;
619
+ var wordsRegExp = REGEXP_EXTENDED_ASCII . test ( subjectString ) ? REGEXP_LATIN_WORD : REGEXP_WORD ;
620
+ return subjectString . replace ( wordsRegExp , function ( word ) {
621
+ var lowerCaseWord = word . toLowerCase ( ) ;
622
+ return ignoreWordsArray . indexOf ( lowerCaseWord ) !== - 1 ? lowerCaseWord : capitalize ( lowerCaseWord , true ) ;
623
+ } ) ;
624
+ }
625
+
599
626
/**
600
627
* Clip the number to interval `downLimit` to `upLimit`.
601
628
*
@@ -2295,7 +2322,7 @@ function removeCombiningMarks(character, cleanCharacter) {
2295
2322
function latinise ( subject ) {
2296
2323
var subjectString = coerceToString ( subject ) ;
2297
2324
if ( subjectString === '' ) {
2298
- return subjectString ;
2325
+ return '' ;
2299
2326
}
2300
2327
return subjectString . replace ( REGEXP_NON_LATIN , getLatinCharacter ) . replace ( REGEXP_COMBINING_MARKS , removeCombiningMarks ) ;
2301
2328
}
@@ -2574,6 +2601,8 @@ function splice(subject, start, deleteCount, toAdd) {
2574
2601
return subjectString . slice ( 0 , startPosition ) + toAddString + subjectString . slice ( startPosition + deleteCountNumber ) ;
2575
2602
}
2576
2603
2604
+ var reduce$1 = Array . prototype . reduce ;
2605
+
2577
2606
/**
2578
2607
* Removes whitespaces from the left side of the `subject`.
2579
2608
*
@@ -2582,7 +2611,7 @@ function splice(subject, start, deleteCount, toAdd) {
2582
2611
* @since 1.0.0
2583
2612
* @memberOf Manipulate
2584
2613
* @param {string } [subject=''] The string to trim.
2585
- * @param {string } [whitespace=whitespace] The whitespace characters to trim.
2614
+ * @param {string } [whitespace=whitespace] The whitespace characters to trim. List all characters that you want to be stripped.
2586
2615
* @return {string } Returns the trimmed string.
2587
2616
* @example
2588
2617
* v.trimLeft(' Starship Troopers');
@@ -2600,19 +2629,18 @@ function trimLeft(subject, whitespace$$1) {
2600
2629
if ( isNil ( whitespaceString ) ) {
2601
2630
return subjectString . replace ( REGEXP_TRIM_LEFT , '' ) ;
2602
2631
}
2603
- var whitespaceLength = whitespaceString . length ;
2604
2632
var matchWhitespace = true ;
2605
- var totalWhitespaceLength = 0 ;
2606
- while ( matchWhitespace ) {
2607
- if ( subjectString . indexOf ( whitespaceString , totalWhitespaceLength ) === totalWhitespaceLength ) {
2608
- totalWhitespaceLength += whitespaceLength ;
2609
- } else {
2610
- matchWhitespace = false ;
2633
+ return reduce$1 . call ( subjectString , function ( trimmed , character ) {
2634
+ if ( matchWhitespace && includes ( whitespaceString , character ) ) {
2635
+ return trimmed ;
2611
2636
}
2612
- }
2613
- return subjectString . substring ( totalWhitespaceLength ) ;
2637
+ matchWhitespace = false ;
2638
+ return trimmed + character ;
2639
+ } , '' ) ;
2614
2640
}
2615
2641
2642
+ var reduceRight = Array . prototype . reduceRight ;
2643
+
2616
2644
/**
2617
2645
* Removes whitespaces from the right side of the `subject`.
2618
2646
*
@@ -2621,7 +2649,7 @@ function trimLeft(subject, whitespace$$1) {
2621
2649
* @since 1.0.0
2622
2650
* @memberOf Manipulate
2623
2651
* @param {string } [subject=''] The string to trim.
2624
- * @param {string } [whitespace=whitespace] The whitespace characters to trim.
2652
+ * @param {string } [whitespace=whitespace] The whitespace characters to trim. List all characters that you want to be stripped.
2625
2653
* @return {string } Returns the trimmed string.
2626
2654
* @example
2627
2655
* v.trimRight('the fire rises ');
@@ -2639,20 +2667,14 @@ function trimRight(subject, whitespace$$1) {
2639
2667
if ( isNil ( whitespaceString ) ) {
2640
2668
return subjectString . replace ( REGEXP_TRIM_RIGHT , '' ) ;
2641
2669
}
2642
- var whitespaceLength = whitespaceString . length ;
2643
- var subjectLength = subjectString . length ;
2644
2670
var matchWhitespace = true ;
2645
- var totalWhitespaceLength = 0 ;
2646
- var position = void 0 ;
2647
- while ( matchWhitespace ) {
2648
- position = subjectLength - totalWhitespaceLength - whitespaceLength ;
2649
- if ( subjectString . indexOf ( whitespaceString , position ) === position ) {
2650
- totalWhitespaceLength += whitespaceLength ;
2651
- } else {
2652
- matchWhitespace = false ;
2671
+ return reduceRight . call ( subjectString , function ( trimmed , character ) {
2672
+ if ( matchWhitespace && includes ( whitespaceString , character ) ) {
2673
+ return trimmed ;
2653
2674
}
2654
- }
2655
- return subjectString . substring ( 0 , subjectLength - totalWhitespaceLength ) ;
2675
+ matchWhitespace = false ;
2676
+ return character + trimmed ;
2677
+ } , '' ) ;
2656
2678
}
2657
2679
2658
2680
/**
@@ -2663,7 +2685,7 @@ function trimRight(subject, whitespace$$1) {
2663
2685
* @since 1.0.0
2664
2686
* @memberOf Manipulate
2665
2687
* @param {string } [subject=''] The string to trim.
2666
- * @param {string } [whitespace=whitespace] The whitespace characters to trim.
2688
+ * @param {string } [whitespace=whitespace] The whitespace characters to trim. List all characters that you want to be stripped.
2667
2689
* @return {string } Returns the trimmed string.
2668
2690
* @example
2669
2691
* v.trim(' Mother nature ');
@@ -3185,6 +3207,37 @@ function split(subject, separator, limit) {
3185
3207
return subjectString . split ( separator , limit ) ;
3186
3208
}
3187
3209
3210
+ var BYRE_ORDER_MARK = '\uFEFF' ;
3211
+
3212
+ /**
3213
+ * Strips the byte order mark (BOM) from the beginning of `subject`.
3214
+ *
3215
+ * @function stripBom
3216
+ * @static
3217
+ * @since 1.2.0
3218
+ * @memberOf Strip
3219
+ * @param {string } [subject=''] The string to strip from.
3220
+ * @return {string } Returns the stripped string.
3221
+ * @example
3222
+ *
3223
+ * v.stripBom('\uFEFFsummertime sadness');
3224
+ * // => 'summertime sadness'
3225
+ *
3226
+ * v.stripBom('summertime happiness');
3227
+ * // => 'summertime happiness'
3228
+ *
3229
+ */
3230
+ function trim$1 ( subject ) {
3231
+ var subjectString = coerceToString ( subject ) ;
3232
+ if ( subjectString === '' ) {
3233
+ return '' ;
3234
+ }
3235
+ if ( subjectString [ 0 ] === BYRE_ORDER_MARK ) {
3236
+ return subjectString . substring ( 1 ) ;
3237
+ }
3238
+ return subjectString ;
3239
+ }
3240
+
3188
3241
/**
3189
3242
* Checks whether `subject` contains substring at specific `index`.
3190
3243
*
@@ -3227,10 +3280,11 @@ var STATE_NON_WHITESPACE = 1;
3227
3280
var STATE_DONE = 2 ;
3228
3281
3229
3282
/**
3230
- * Parses the tag name from html content
3283
+ * Parses the tag name from html content.
3231
3284
*
3232
- * @param {string } tagContent The tag content
3233
- * @return {string } Returns the tag name
3285
+ * @ignore
3286
+ * @param {string } tagContent The tag content.
3287
+ * @return {string } Returns the tag name.
3234
3288
*/
3235
3289
function parseTagName ( tagContent ) {
3236
3290
var state = STATE_START_TAG ;
@@ -3290,7 +3344,7 @@ var STATE_COMMENT = 3;
3290
3344
* v.stripTags('Sun<br/>set', '', '-');
3291
3345
* // => 'Sun-set'
3292
3346
*/
3293
- function trim$1 ( subject , allowableTags , replacement ) {
3347
+ function trim$2 ( subject , allowableTags , replacement ) {
3294
3348
subject = coerceToString ( subject ) ;
3295
3349
if ( subject === '' ) {
3296
3350
return '' ;
@@ -3413,7 +3467,6 @@ function trim$1(subject, allowableTags, replacement) {
3413
3467
}
3414
3468
}
3415
3469
}
3416
-
3417
3470
return output ;
3418
3471
}
3419
3472
@@ -3532,6 +3585,7 @@ var functions = {
3532
3585
kebabCase : kebabCase ,
3533
3586
lowerCase : lowerCase ,
3534
3587
snakeCase : snakeCase ,
3588
+ titleCase : titleCase ,
3535
3589
upperCase : upperCase ,
3536
3590
3537
3591
count : count ,
@@ -3599,7 +3653,8 @@ var functions = {
3599
3653
split : split ,
3600
3654
words : words ,
3601
3655
3602
- stripTags : trim$1 ,
3656
+ stripBom : trim$1 ,
3657
+ stripTags : trim$2 ,
3603
3658
3604
3659
noConflict : noConflict ,
3605
3660
version : version
0 commit comments