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 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
|
/*
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// TypeScript Version: 2.0
/* tslint:disable:max-line-length */
/* tslint:disable:max-file-line-count */
import acronym = require( './../../acronym' );
import camelcase = require( './../../camelcase' );
import capitalize = require( './../../capitalize' );
import codePointAt = require( './../../code-point-at' );
import constantcase = require( './../../constantcase' );
import endsWith = require( './../../ends-with' );
import fromCodePoint = require( './../../from-code-point' );
import kebabcase = require( './../../kebabcase' );
import lpad = require( './../../left-pad' );
import ltrim = require( './../../left-trim' );
import ltrimN = require( './../../left-trim-n' );
import lowercase = require( './../../lowercase' );
import nextGraphemeClusterBreak = require( './../../next-grapheme-cluster-break' );
import numGraphemeClusters = require( './../../num-grapheme-clusters' );
import pad = require( './../../pad' );
import pascalcase = require( './../../pascalcase' );
import percentEncode = require( './../../percent-encode' );
import prevGraphemeClusterBreak = require( './../../prev-grapheme-cluster-break' );
import removeFirst = require( './../../remove-first' );
import removeLast = require( './../../remove-last' );
import removePunctuation = require( './../../remove-punctuation' );
import removeUTF8BOM = require( './../../remove-utf8-bom' );
import removeWords = require( './../../remove-words' );
import repeat = require( './../../repeat' );
import replace = require( './../../replace' );
import reverseString = require( './../../reverse' );
import rpad = require( './../../right-pad' );
import rtrim = require( './../../right-trim' );
import rtrimN = require( './../../right-trim-n' );
import snakecase = require( './../../snakecase' );
import splitGraphemeClusters = require( './../../split-grapheme-clusters' );
import format = require( './../../format' );
import startcase = require( './../../startcase' );
import startsWith = require( './../../starts-with' );
import substringAfter = require( './../../substring-after' );
import substringAfterLast = require( './../../substring-after-last' );
import substringBefore = require( './../../substring-before' );
import substringBeforeLast = require( './../../substring-before-last' );
import trim = require( './../../trim' );
import truncate = require( './../../truncate' );
import truncateMiddle = require( './../../truncate-middle' );
import uncapitalize = require( './../../uncapitalize' );
import uppercase = require( './../../uppercase' );
import utf16ToUTF8Array = require( './../../utf16-to-utf8-array' );
/**
* Interface describing the `string` namespace.
*/
interface Namespace {
/**
* Generates an acronym for a given string.
*
* @param str - input string
* @param options - function options
* @param options.stopwords - custom stop words
* @returns generated acronym
*
* @example
* var out = ns.acronym( 'the quick brown fox' );
* // returns 'QBF'
*
* @example
* var out = ns.acronym( 'Hard-boiled eggs' );
* // returns 'HBE'
*
* @example
* var out = ns.acronym( 'National Association of Securities Dealers Automated Quotation' );
* // returns 'NASDAQ'
*/
acronym: typeof acronym;
/**
* Converts a string to camel case.
*
* @param str - string to convert
* @returns a camel-cased string
*
* @example
* var str = ns.camelcase( 'Hello World!' );
* // returns 'helloWorld'
*
* @example
* var str = ns.camelcase( 'foo_bar' );
* // returns 'fooBar'
*
* @example
* var str = ns.camelcase( 'foo-bar' );
* // returns 'fooBar'
*/
camelcase: typeof camelcase;
/**
* Capitalizes the first character in a string.
*
* @param str - input string
* @returns capitalized string
*
* @example
* var out = ns.capitalize( 'last man standing' );
* // returns 'Last man standing'
*
* @example
* var out = ns.capitalize( 'presidential election' );
* // returns 'Presidential election'
*
* @example
* var out = ns.capitalize( 'javaScript' );
* // returns 'JavaScript'
*
* @example
* var out = ns.capitalize( 'Hidden Treasures' );
* // returns 'Hidden Treasures'
*/
capitalize: typeof capitalize;
/**
* Returns a Unicode code point from a string at specified position.
*
* @param str - input string
* @param idx - position
* @param backward - backward iteration for low surrogates (default: false)
* @throws first argument must be a string
* @throws second argument must be a nonnegative integer
* @throws third argument must be a boolean
* @throws position must be a valid index in string
* @returns code point
*
* @example
* var str = ns.codePointAt( 'अनुच्छेद', 2 );
* // returns 2369
*
* str = ns.codePointAt( '🌷', 1, true );
* // returns 127799
*/
codePointAt: typeof codePointAt;
/**
* Converts a string to constant case.
*
* @param str - string to convert
* @returns a constant-cased string
*
* @example
* var str = ns.constantcase( 'beep' );
* // returns 'BEEP'
*
* @example
* var str = ns.constantcase( 'beep boop' );
* // returns 'BEEP_BOOP'
*
* @example
* var str = ns.constantcase( 'Hello World!' );
* // returns 'HELLO_WORLD'
*/
constantcase: typeof constantcase;
/**
* Test if a string ends with the characters of another string.
*
* @param str - input string
* @param search - search string
* @param len - substring length (default: str.length)
* @returns boolean indicating if the input string ends with the search string
*
* @example
* var bool = ns.endsWith( 'Remember the story I used to tell you when you were a boy?', 'boy?' );
* // returns true
*
* @example
* var bool = ns.endsWith( 'Remember the story I used to tell you when you were a boy?', 'Boy?' );
* // returns false
*
* @example
* var bool = ns.endsWith( 'To be, or not to be, that is the question.', 'to be' );
* // returns false
*
* @example
* var bool = ns.endsWith( 'To be, or not to be, that is the question.', 'to be', 19 );
* // returns true
*
* @example
* var bool = ns.endsWith( 'To be, or not to be, that is the question.', 'to be', -23 );
* // returns true
*/
endsWith: typeof endsWith;
/**
* Creates a string from a sequence of Unicode code points.
*
* ## Notes
*
* - In addition to multiple arguments, the function also supports providing an array-like object as a single argument containing a sequence of Unicode code points.
*
* @param pt - sequence of code points
* @throws must provide either an array-like object of code points or one or more code points as separate arguments
* @throws a code point must be a nonnegative integer
* @throws must provide a valid Unicode code point
* @returns created string
*
* @example
* var str = ns.fromCodePoint( 9731 );
* // returns '☃'
*/
fromCodePoint: typeof fromCodePoint;
/**
* Converts a string to kebab case.
*
* @param str - string to convert
* @returns a kebab-cased string
*
* @example
* var str = ns.kebabcase( 'fooBar' );
* // returns 'foo-bar'
*
* @example
* var str = ns.kebabcase( 'foo_bar' );
* // returns 'foo-bar'
*
* @example
* var str = ns.kebabcase( 'foo-bar' );
* // returns 'foo-bar'
*/
kebabcase: typeof kebabcase;
/**
* Left pads a string such that the padded string has a length of at least `len`.
*
* ## Notes
*
* - An output string is not guaranteed to have a length of exactly `len`, but to have a length of at least `len`. To generate a padded string having a length equal to `len`, post-process a padded string by trimming off excess characters.
*
* @param str - string to pad
* @param len - minimum string length
* @param pad - string used to pad (default: ' ')
* @throws second argument must be a nonnegative integer
* @throws padding must have a length greater than `0`
* @returns padded string
*
* @example
* var str = ns.lpad( 'a', 5 );
* // returns ' a'
*
* @example
* var str = ns.lpad( 'beep', 10, 'b' );
* // returns 'bbbbbbbeep'
*
* @example
* var str = ns.lpad( 'boop', 12, 'beep' );
* // returns 'beepbeepboop'
*/
lpad: typeof lpad;
/**
* Trims whitespace characters from the beginning of a string.
*
* @param str - input string
* @returns trimmed string
*
* @example
* var out = ns.ltrim( ' Whitespace ' );
* // returns 'Whitespace '
*
* @example
* var out = ns.ltrim( '\t\t\tTabs\t\t\t' );
* // returns 'Tabs\t\t\t'
*
* @example
* var out = ns.ltrim( '\n\n\nNew Lines\n\n\n' );
* // returns 'New Lines\n\n\n'
*/
ltrim: typeof ltrim;
/**
* Trims `n` characters from the beginning of a string.
*
* @param str - input string
* @param n - number of characters to trim
* @param chars - characters to trim (default: whitespace characters)
* @returns trimmed string
*
* @example
* var str = ' abc ';
* var out = ns.ltrimN( str, 2 );
* // returns ' abc '
*
* @example
* var str = ' abc ';
* var out = ns.ltrimN( str, str.length );
* // returns 'abc '
*
* @example
* var str = '~~abc!~~';
* var out = ns.ltrimN( str, str.length, [ '~', '!' ] );
* // returns 'abc!~~'
*
* @example
* var str = '🤖👨🏼🎨🤖👨🏼🎨🤖👨🏼🎨';
* var out = ns.ltrimN( str, str.length, '👨🏼🎨🤖' );
* // returns ''
*/
ltrimN: typeof ltrimN;
/**
* Converts a string to lowercase.
*
* @param str - string to convert
* @returns lowercase string
*
* @example
* var str = ns.lowercase( 'bEEp' );
* // returns 'beep'
*/
lowercase: typeof lowercase;
/**
* Returns the next extended grapheme cluster break in a string after a specified position.
*
* @param str - input string
* @param fromIndex - position (default: 0)
* @throws first argument must be a string
* @throws second argument must be an integer
* @returns next grapheme break position
*
* @example
* var out = ns.nextGraphemeClusterBreak( 'अनुच्छेद', 1 );
* // returns 3
*
* out = ns.nextGraphemeClusterBreak( '🌷' );
* // returns -1
*/
nextGraphemeClusterBreak: typeof nextGraphemeClusterBreak;
/**
* Returns the number of grapheme clusters in a string.
*
* @param str - input string
* @returns number of grapheme clusters
*
* @example
* var out = ns.numGraphemeClusters( 'last man standing' );
* // returns 17
*
* @example
* var out = ns.numGraphemeClusters( 'presidential election' );
* // returns 21
*
* @example
* var out = ns.numGraphemeClusters( '🌷' );
* // returns 1
*
* @example
* var out = ns.numGraphemeClusters( 'अनुच्छेद' );
* // returns 5
*/
numGraphemeClusters: typeof numGraphemeClusters;
/**
* Pads a string such that the padded string has a length of `len`.
*
* @param str - string to pad
* @param len - string length
* @param options - function options
* @param options.lpad - string used to left pad (default: '')
* @param options.rpad - string used to right pad (default: ' ')
* @param options.centerRight - boolean indicating whether to center right in the event of a tie (default: false)
* @throws second argument must be a nonnegative integer
* @throws must provide valid options
* @throws at least one padding must have a length greater than `0`
* @returns padded string
*
* @example
* var str = ns.pad( 'a', 5 );
* // returns 'a '
*
* @example
* var str = ns.pad( 'a', 10, {
* 'lpad': 'b'
* });
* // returns 'bbbbbbbbba'
*
* @example
* var str = ns.pad( 'a', 12, {
* 'rpad': 'b'
* });
* // returns 'abbbbbbbbbbb'
*
* @example
* var opts = {
* 'lpad': 'a',
* 'rpad': 'c'
* };
* var str = ns.pad( 'b', 10, opts );
* // returns 'aaaabccccc'
*
* @example
* var opts = {
* 'lpad': 'a',
* 'rpad': 'c',
* 'centerRight': true
* };
* var str = ns.pad( 'b', 10, opts );
* // returns 'aaaaabcccc'
*/
pad: typeof pad;
/**
* Converts a string to Pascal case.
*
* @param str - string to convert
* @returns a Pascal-cased string
*
* @example
* var str = ns.pascalcase( 'Hello World!' );
* // returns 'HelloWorld'
*
* @example
* var str = ns.pascalcase( 'foo_bar' );
* // returns 'FooBar'
*
* @example
* var str = ns.pascalcase( 'foo-bar' );
* // returns 'FooBar'
*/
pascalcase: typeof pascalcase;
/**
* Percent-encode a UTF-16 encoded string according to [RFC 3986][1].
*
* [1]: https://tools.ietf.org/html/rfc3986#section-2.1
*
* @param str - string to percent-encode
* @returns percent-encoded string
*
* @example
* var str1 = 'Ladies + Gentlemen';
*
* var str2 = ns.percentEncode( str1 );
* // returns 'Ladies%20%2B%20Gentlemen'
*/
percentEncode: typeof percentEncode;
/**
* Returns the previous extended grapheme cluster break in a string before a specified position.
*
* @param str - input string
* @param fromIndex - position (default: str.length-1)
* @throws first argument must be a string
* @throws second argument must be an integer
* @returns previous grapheme break position
*
* @example
* var out = ns.prevGraphemeClusterBreak( 'अनुच्छेद', 2 );
* // returns 0
*
* out = ns.prevGraphemeClusterBreak( '🌷', 1 );
* // returns -1
*/
prevGraphemeClusterBreak: typeof prevGraphemeClusterBreak;
/**
* Removes the first character(s) of a string.
*
* @param str - input string
* @param n - number of characters to remove (default: 1)
* @returns updated string
*
* @example
* var out = ns.removeFirst( 'last man standing' );
* // returns 'ast man standing'
*
* @example
* var out = ns.removeFirst( 'presidential election' );
* // returns 'residential election'
*
* @example
* var out = ns.removeFirst( 'javaScript' );
* // returns 'avaScript'
*
* @example
* var out = ns.removeFirst( 'Hidden Treasures' );
* // returns 'idden Treasures'
*
* @example
* var out = ns.removeFirst( '🐶🐮🐷🐰🐸', 2 );
* // returns '🐷🐰🐸'
*
* @example
* var out = ns.removeFirst( 'foo bar', 4 );
* // returns 'bar'
*/
removeFirst: typeof removeFirst;
/**
* Removes the last character(s) of a string.
*
* @param str - input string
* @param n - number of characters to remove (default: 1)
* @returns updated string
*
* @example
* var out = ns.removeLast( 'last man standing' );
* // returns 'last man standin'
*
* @example
* var out = ns.removeLast( 'presidential election' );
* // returns 'presidential electio'
*
* @example
* var out = ns.removeLast( 'javaScript' );
* // returns 'javaScrip'
*
* @example
* var out = ns.removeLast( 'Hidden Treasures' );
* // returns 'Hidden Treasure'
*
* @example
* var out = ns.removeLast( 'leader', 2 );
* // returns 'lead'
*/
removeLast: typeof removeLast;
/**
* Removes punctuation characters from a string.
*
* @param str - input string
* @returns output string
*
* @example
* var str = 'Sun Tzu said: "A leader leads by example not by force."';
* var out = ns.removePunctuation( str );
* // returns 'Sun Tzu said A leader leads by example not by force'
*
* @example
* var str = 'Double, double, toil and trouble; Fire burn, and cauldron bubble!';
* var out = ns.removePunctuation( str );
* // returns 'Double double toil and trouble Fire burn and cauldron bubble'
*
* @example
* var str = 'This module removes these characters: `{}[]:,!/<>().;~|?\'"';
* var out = ns.removePunctuation( str );
* // returns 'This module removes these characters '
*/
removePunctuation: typeof removePunctuation;
/**
* Removes a UTF-8 byte order mark (BOM) from the beginning of a string.
*
* ## Notes
*
* - A UTF-8 byte order mark ([BOM][1]) is the byte sequence `0xEF,0xBB,0xBF`.
* - To convert a UTF-8 encoded `Buffer` to a `string`, the `Buffer` must be converted to [UTF-16][2]. The BOM thus gets converted to the single 16-bit code point `'\ufeff'` (UTF-16 BOM).
*
* [1]: https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8
* [2]: http://es5.github.io/#x4.3.16
*
* @param str - input string
* @returns string with BOM removed
*
* @example
* var str = ns.removeUTF8BOM( '\ufeffbeep' );
* // returns 'beep'
*/
removeUTF8BOM: typeof removeUTF8BOM;
/**
* Removes a list of words from a string.
*
* @param str - input string
* @param words - array of words to be removed
* @param ignoreCase - boolean indicating whether to perform a case-insensitive operation (default: false)
* @returns output string
*
* @example
* var str = 'beep boop Foo bar';
* var out = ns.removeWords( str, [ 'boop', 'foo' ] );
* // returns 'beep Foo bar'
*
* @example
* var str = 'beep boop Foo bar';
* var out = ns.removeWords( str, [ 'boop', 'foo' ], true );
* // returns 'beep bar'
*/
removeWords: typeof removeWords;
/**
* Repeats a string `n` times and returns the concatenated result.
*
* @param str - string to repeat
* @param n - number of times to repeat the string
* @returns repeated string
*
* @example
* var str = ns.repeat( 'a', 5 );
* // returns 'aaaaa'
*
* @example
* var str = ns.repeat( '', 100 );
* // returns ''
*
* @example
* var str = ns.repeat( 'beep', 0 );
* // returns ''
*/
repeat: typeof repeat;
/**
* Replace search occurrences with a replacement string.
*
* ## Notes
*
* - When provided a `string` as the `search` value, the function replaces *all* occurrences. To remove only the first match, use a regular expression.
*
* @param str - input string
* @param search - search expression
* @param newval - replacement value or function
* @returns new string containing replacement(s)
*
* @example
* var str = 'beep';
* var out = ns.replace( str, 'e', 'o' );
* // returns 'boop'
*
* @example
* var str = 'Hello World';
* var out = ns.replace( str, /world/i, 'Mr. President' );
* // returns 'Hello Mr. President'
*
* @example
* var capitalize = require( `@stdlib/string/capitalize` );
*
* var str = 'Oranges and lemons say the bells of St. Clement\'s';
*
* function ns.replacer( match, p1 ) {
* return capitalize( p1 );
* }
*
* var out = ns.replace( str, /([^\s]*)/gi, ns.replacer);
* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s'
*/
replace: typeof replace;
/**
* Reverses a string.
*
* @param str - input string
* @returns reversed string
*
* @example
* var out = ns.reverseString( 'last man standing' );
* // returns 'gnidnats nam tsal'
*
* @example
* var out = ns.reverseString( 'presidential election' );
* // returns 'noitcele laitnediserp'
*
* @example
* var out = ns.reverseString( 'javaScript' );
* // returns 'tpircSavaj'
*
* @example
* var out = ns.reverseString( 'Hidden Treasures' );
* // returns 'serusaerT neddiH'
*/
reverseString: typeof reverseString;
/**
* Right pads a string such that the padded string has a length of at least `len`.
*
* ## Notes
*
* - An output string is not guaranteed to have a length of exactly `len`, but to have a length of at least `len`. To generate a padded string having a length equal to `len`, post-process a padded string by trimming off excess characters.
*
* @param str - string to pad
* @param len - minimum string length
* @param pad - string used to pad (default: ' ')
* @throws second argument must be a nonnegative integer
* @throws padding must have a length greater than `0`
* @returns padded string
*
* @example
* var str = ns.rpad( 'a', 5 );
* // returns 'a '
*
* @example
* var str = ns.rpad( 'beep', 10, 'p' );
* // returns 'beeppppppp'
*
* @example
* var str = ns.rpad( 'beep', 12, 'boop' );
* // returns 'beepboopboop'
*/
rpad: typeof rpad;
/**
* Trims whitespace from the end of a string.
*
* @param str - input string
* @returns trimmed string
*
* @example
* var out = ns.rtrim( ' Whitespace ' );
* // returns ' Whitespace'
*
* @example
* var out = ns.rtrim( '\t\t\tTabs\t\t\t' );
* // returns '\t\t\tTabs'
*
* @example
* var out = ns.rtrim( '\n\n\nNew Lines\n\n\n' );
* // returns '\n\n\nNew Lines'
*/
rtrim: typeof rtrim;
/**
* Trims `n` characters from the end of a string.
*
* @param str - input string
* @param n - number of characters to trim
* @param chars - characters to trim (default: whitespace characters)
* @returns trimmed string
*
* @example
* var str = ' abc ';
* var out = ns.rtrimN( str, 2 );
* // returns ' abc '
*
* @example
* var str = ' abc ';
* var out = ns.rtrimN( str, str.length );
* // returns ' abc'
*
* @example
* var str = '~~abc!~~';
* var out = ns.rtrimN( str, str.length, [ '~', '!' ] );
* // returns '~~abc'
*
* @example
* var str = '🤖👨🏼🎨🤖👨🏼🎨🤖👨🏼🎨';
* var out = ns.rtrimN( str, str.length, '👨🏼🎨🤖' );
* // returns ''
*/
rtrimN: typeof rtrimN;
/**
* Converts a string to snake case.
*
* @param str - string to convert
* @returns a snake-cased string
*
* @example
* var str = ns.snakecase( 'fooBar' );
* // returns 'foo_bar'
*
* @example
* var str = ns.snakecase( 'foo-bar' );
* // returns 'foo_bar'
*
* @example
* var str = ns.snakecase( 'foo_bar' );
* // returns 'foo_bar'
*/
snakecase: typeof snakecase;
/**
* Splits a string by its grapheme cluster breaks.
*
* @param str - input string
* @returns array of grapheme clusters
*
* @example
* var out = ns.splitGraphemeClusters( 'café' );
* // returns [ 'c', 'a', 'f', 'é' ]
*
* @example
* var out = ns.splitGraphemeClusters( '🍕🍕🍕' );
* // returns [ '🍕', '🍕', '🍕' ]
*/
splitGraphemeClusters: typeof splitGraphemeClusters;
/**
* Inserts supplied variable values into a format string.
*
* @param str - input string
* @param ...args - variable values
* @throws invalid flags
* @returns formatted string
*
* @example
* var str = ns.format( 'Hello %s!', 'world' );
* // returns 'Hello world!'
*
* @example
* var str = ns.format( 'Pi: ~%.2f', 3.141592653589793 );
* // returns 'Pi: ~3.14'
*/
format: typeof format;
/**
* Capitalizes the first letter of each word in an input string.
*
* @param str - string to convert
* @returns start case string
*
* @example
* var str = ns.startcase( 'beep boop foo bar' );
* // returns 'Beep Boop Foo Bar'
*/
startcase: typeof startcase;
/**
* Tests if a string starts with the characters of another string.
*
* @param str - input string
* @param search - search string
* @param position - position at which to start searching (default: 0)
* @returns boolean indicating if the input string starts with the search string
*
* @example
* var bool = ns.startsWith( 'Remember the story I used to tell you when you were a boy?', 'Remember' );
* // returns true
*
* @example
* var bool = ns.startsWith( 'Remember the story I used to tell you when you were a boy?', 'Remember, remember' );
* // returns false
*
* @example
* var bool = ns.startsWith( 'To be, or not to be, that is the question.', 'To be' );
* // returns true
*
* @example
* var bool = ns.startsWith( 'To be, or not to be, that is the question.', 'to be' );
* // returns false
*
* @example
* var bool = ns.startsWith( 'To be, or not to be, that is the question.', 'to be', 14 );
* // returns true
*
* @example
* var bool = ns.startsWith( 'To be, or not to be, that is the question.', 'quest', -9 );
* // returns true
*/
startsWith: typeof startsWith;
/**
* Returns the part of a string after a specified substring.
*
* @param str - input string
* @param search - search string
* @param fromIndex - index at which to start the search (default: 0)
* @returns substring
*
* @example
* var out = ns.substringAfter( 'Hello, world!', ', ' );
* // returns 'world!'
*
* @example
* var out = ns.substringAfter( 'beep boop', 'beep' );
* // returns ' boop'
*
* @example
* var out = ns.substringAfter( 'beep boop', 'boop' );
* // returns ''
*
* @example
* var out = ns.substringAfter( 'beep boop', 'xyz' );
* // returns ''
*
* @example
* var out = ns.substringAfter( 'beep boop', 'beep', 5 );
* // returns ''
*
* @example
* var out = ns.substringAfter( 'beep boop beep baz', 'beep', 5 );
* // returns ' baz'
*/
substringAfter: typeof substringAfter;
/**
* Returns the part of a string after the last occurrence of a specified substring.
*
* @param str - input string
* @param search - search value
* @param fromIndex - index of last character to be considered beginning of a match (default: `str.length`)
* @returns substring
*
* @example
* var out = ns.substringAfterLast( 'beep boop', 'b' );
* // returns 'oop'
*
* @example
* var out = ns.substringAfterLast( 'beep boop', 'o' );
* // returns 'p'
*
* @example
* var out = ns.substringAfterLast( 'Hello World', 'o' );
* // returns 'rld'
*
* @example
* var out = ns.substringAfterLast( 'Hello World', '!' );
* // returns ''
*
* @example
* var out = ns.substringAfterLast( 'Hello World', '' );
* // returns ''
*
* @example
* var out = ns.substringAfterLast( 'beep boop baz', 'p b', 6 );
* // returns 'oop baz'
*/
substringAfterLast: typeof substringAfterLast;
/**
* Returns the part of a string before a specified substring.
*
* @param str - input string
* @param search - search string
* @returns substring
*
* @example
* var out = ns.substringBefore( 'beep boop', ' ' );
* // returns 'beep'
*
* @example
* var out = ns.substringBefore( 'beep boop', 'p' );
* // returns 'bee'
*
* @example
* var out = ns.substringBefore( 'Hello World!', '' );
* // returns ''
*
* @example
* var out = ns.substringBefore( 'Hello World!', 'XYZ' );
* // returns 'Hello World!'
*/
substringBefore: typeof substringBefore;
/**
* Returns the part of a string before the last occurrence of a specified substring.
*
* @param str - input string
* @param search - search value
* @returns substring
*
* @example
* var out = ns.substringBeforeLast( 'abcba', 'b' );
* // returns 'abc'
*
* @example
* var out = ns.substringBeforeLast( 'Hello World, my friend!', ' ' );
* // returns 'Hello World, my'
*
* @example
* var out = ns.substringBeforeLast( 'abcba', ' ' );
* // returns 'abcba'
*
* @example
* var out = ns.substringBeforeLast( 'abcba', '' );
* // returns 'abcba'
*/
substringBeforeLast: typeof substringBeforeLast;
/**
* Trim whitespace characters from beginning and end of a string.
*
* @param str - input string
* @returns trimmed string
*
* @example
* var out = ns.trim( ' Whitespace ' );
* // returns 'Whitespace'
*
* @example
* var out = ns.trim( '\t\t\tTabs\t\t\t' );
* // returns 'Tabs'
*
* @example
* var out = ns.trim( '\n\n\nNew Lines\n\n\n' );
* // returns 'New Lines'
*/
trim: typeof trim;
/**
* Truncates a string to a specified length.
*
* @param str - input string
* @param len - output string length (including ending)
* @param ending - custom ending (default: `...`)
* @returns truncated string
*
* @example
* var out = ns.truncate( 'beep boop', 7 );
* // returns 'beep...'
*
* @example
* var out = ns.truncate( 'beep boop', 7, '|' );
* // returns 'beep b|'
*/
truncate: typeof truncate;
/**
* Truncates a string in the middle to a specified length.
*
* @param str - input string
* @param len - output string length (including sequence)
* @param seq - custom replacement sequence (default: `...`)
* @returns truncated string
*
* @example
* var str = 'beep boop';
* var out = ns.truncateMiddle( str, 5 );
* // returns 'b...p'
*
* @example
* var str = 'beep boop';
* var out = ns.truncateMiddle( str, 5, '>>>' );
* // returns 'b>>>p'
*
* @example
* var str = 'beep boop';
* var out = ns.truncateMiddle( str, 10 );
* // returns 'beep boop'
*
* @example
* var str = 'beep boop';
* var out = ns.truncateMiddle( str, 0 );
* // returns ''
*
* @example
* var str = 'beep boop';
* var out = ns.truncateMiddle( str, 2 );
* // returns '..'
*
* @example
* var str = '🐺 Wolf Brothers 🐺';
* var out = ns.truncateMiddle( str, 7 );
* // returns '🐺 ... 🐺'
*/
truncateMiddle: typeof truncateMiddle;
/**
* Uncapitalizes the first character of a string.
*
* @param str - input string
* @returns input string with first character converted to lowercase
*
* @example
* var out = ns.uncapitalize( 'Last man standing' );
* // returns 'last man standing'
*
* @example
* var out = ns.uncapitalize( 'Presidential election' );
* // returns 'presidential election'
*
* @example
* var out = ns.uncapitalize( 'JavaScript' );
* // returns 'javaScript'
*
* @example
* var out = ns.uncapitalize( 'Hidden Treasures' );
* // returns 'hidden Treasures'
*/
uncapitalize: typeof uncapitalize;
/**
* Converts a string to uppercase.
*
* @param str - string to convert
* @returns uppercase string
*
* @example
* var str = ns.uppercase( 'bEEp' );
* // returns 'BEEP'
*/
uppercase: typeof uppercase;
/**
* Converts a UTF-16 encoded string to an array of integers using UTF-8 encoding.
*
* ## Notes
*
* - The following byte sequences are used to represent a character. The sequence depends on the code point:
*
* 0x00000000 - 0x0000007F:
* 0xxxxxxx
*
* 0x00000080 - 0x000007FF:
* 110xxxxx 10xxxxxx
*
* 0x00000800 - 0x0000FFFF:
* 1110xxxx 10xxxxxx 10xxxxxx
*
* 0x00010000 - 0x001FFFFF:
* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
*
* - The `x` bit positions correspond to code point bits.
* - Only the shortest possible multi-byte sequence which can represent a code point is used.
*
* @param str - string to convert
* @returns array of integers
* @see [UTF-8]{@link https://en.wikipedia.org/wiki/UTF-8}
* @see [Stack Overflow]{@link https://stackoverflow.com/questions/6240055/manually-converting-unicode-codepoints-into-utf-8-and-utf-16}
*
* @example
* var str = '☃';
* var out = ns.utf16ToUTF8Array( str );
* // returns [ 226, 152, 131 ]
*/
utf16ToUTF8Array: typeof utf16ToUTF8Array;
}
/**
* String manipulation functions.
*/
declare var ns: Namespace;
// EXPORTS //
export = ns;
|