forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sugar.d.ts
5015 lines (4486 loc) · 150 KB
/
sugar.d.ts
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
// Type definitions for Sugar 1.3.9
// Project: http://sugarjs.com/
// Definitions by: Josh Baldwin <https://github.com/jbaldwin/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/*
sugar-1.3.9.d.ts may be freely distributed under the MIT license.
Copyright (c) 2013 Josh Baldwin https://github.com/jbaldwin/sugar.d.ts
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
interface String {
/**
* Adds <str> at [index].<br/> Negative values are also allowed.
* @param str String to add.
* @param index Index where <str> is added. Default = str.length
* @returns Original string with <str> added at [index].
* @extra %insert% is provided as an alias, and is generally more readable when using an index.
* @example
* 'schfifty'.add(' five') -> schfifty five
* 'dopamine'.insert('e', 3) -> dopeamine
* 'spelling eror'.insert('r', -3) -> spelling error
**/
add(str: string, index?: number): string;
/**
* @see add
**/
insert(str: string, index?: number): string;
/**
* Assigns variables to tokens in a string.
* @param objs Variable tokens to assign in the string.
* @returns String with <objs> assigned to variables in the original string.
* @extra If an object is passed, it's properties can be assigned using
* the object's keys. If a non-object (string, number, etc.)
* is passed it can be accessed by the argument number beginning
* with 1 (as with regex tokens). Multiple objects can be passed
* and will be merged together (original objects are unaffected).
* @example
* 'Welcome, Mr. {name}.'.assign({ name: 'Franklin' }) -> 'Welcome, Mr. Franklin.'
* 'You are {1} years old today.'.assign(14) -> 'You are 14 years old today.'
* '{n} and {r}'.assign({ n: 'Cheech' }, { r: 'Chong' }) -> 'Cheech and Chong'
**/
assign(...objs: any[]): string;
/***
* Gets the character(s) at a given index.
* @param index Indicies of the character(s) requested.
* @param loop Loop around the string or stop at the end, default = true.
* @returns Character(s) at the specified indices.
* @extra When [loop] is true, overshooting the end of the string
* (or the beginning) will begin counting from the other end.
* As an alternate syntax, passing multiple indexes will get
* the characters at those indexes.
* @example
* 'jumpy'.at(0) -> 'j'
* 'jumpy'.at(2) -> 'm'
* 'jumpy'.at(5) -> 'j'
* 'jumpy'.at(5, false) -> ''
* 'jumpy'.at(-1) -> 'y'
* 'lucky charms'.at(2,4,6,8) -> ['u','k','y',c']
***/
at(index: number, loop?: boolean): string;
/**
* @see at
* @limitation Typescript does not allow for arguments after a variable argument list.
**/
at(...indicies: number[]): string[];
/**
* Converts underscores and hyphens to camel case.
* @param first If [first] is true the first letter will also be capitalized, default = true
* @returns Camel case version of the string.
* @extra If the Inflections package is included acryonyms can also
* be defined that will be used when camelizing.
* @example
* 'caps_lock'.camelize() -> 'CapsLock'
* 'moz-border-radius'.camelize() -> 'MozBorderRadius'
* 'moz-border-radius'.camelize(false) -> 'mozBorderRadius'
**/
camelize(first?: boolean): string;
/**
* Capitalizes the first character in the string.
* @method capitalize([all] = false)
* @param all Default = false
* @returns String
* @extra If [all] is true, all words in the string will be capitalized.
* @example
*
* 'hello'.capitalize() -> 'Hello'
* 'hello kitty'.capitalize() -> 'Hello kitty'
* 'hello kitty'.capitalize(true) -> 'Hello Kitty'
*
**/
capitalize(all?: boolean): string;
/**
* Runs callback [fn] against each character in the string.
* Returns an array of characters.
* @param fn Callback function for each character in the string.
* @returns string[] with each element containing one character
* in the string.
* @example
* 'jumpy'.chars() -> ['j','u','m','p','y']
* 'jumpy'.chars(function(c) {
* // Called 5 times: "j","u","m","p","y"
* });
**/
chars(fn?: (c: string) => void ): string[];
/**
* Runs callback [fn] against each character code in the string.
Returns an array of character codes.
* @param fn Callback function for each character code in the string.
* @returns number[] with each element containing one character code
* in the string.
* @example
* 'jumpy'.codes() -> [106,117,109,112,121]
* 'jumpy'.codes(function(c) {
* // Called 5 times: 106, 117, 109, 112, 121
* });
***/
codes(fn?: (c: string) => void ): number[];
/**
* Compacts all white space in the string to a single space and trims the ends.
* @returns String with all whitespace compated to a single space.
* @example
* 'too \n much \n space'.compact() -> 'too much space'
* 'enough \n '.compact() -> 'enough'
**/
compact(): string;
/**
* Converts underscores and camel casing to hypens.
* @returns String with underscores and camel casing changed to hypens.
* @example
* 'a_farewell_to_arms'.dasherize() -> 'a-farewell-to-arms'
* 'capsLock'.dasherize() -> 'caps-lock'
**/
dasherize(): string;
/**
* Decodes the string from base64 encoding.
* @returns Decoded base64 string.
* @extra This method wraps the browser native %atob% when available,
* and uses a custom implementation when not available.
* @example
* 'aHR0cDovL3R3aXR0ZXIuY29tLw=='.decodeBase64() -> 'http://twitter.com/'
* 'anVzdCBnb3QgZGVjb2RlZA=='.decodeBase64() -> 'just got decoded!'
**/
decodeBase64(): string;
/**
* Runs callback [fn] against each occurence of [search].
* @param fn Callback function for each occurance of [search].
* If [search] is not provided each character is matched.
* @param search Search item to look for in the string.
* @returns string[] of each item matched in the string.
* @extra Returns an array of matches. [search] may be either
* a string or regex, and defaults to every character in the string.
* @example
* 'jumpy'.each() -> ['j','u','m','p','y']
* 'jumpy'.each(/[r-z]/) -> ['u','y']
* 'jumpy'.each(/[r-z]/, function(m) {
* // Called twice: "u", "y"
* });
**/
each(search: string, fn?: (m: string) => void): string[];
/**
* @see each
**/
each(search: RegExp, fn?: (m: string) => void): string[];
/**
* @see each
**/
each(fn?: (m: string) => void ): string[];
/**
* Encodes the string into base64 encoding.
* @returns Base64 encoded string.
* @extra This method wraps the browser native %btoa% when available,
* and uses a custom implementation when not available.
* @example
* 'gonna get encoded!'.encodeBase64() -> 'Z29ubmEgZ2V0IGVuY29kZWQh'
* 'http://twitter.com/'.encodeBase64() -> 'aHR0cDovL3R3aXR0ZXIuY29tLw=='
**/
encodeBase64(): string;
/**
* Returns true if the string ends with <find>.
* @param find String or RegExp to find at the end of the string.
* @param pos Ending position to search for, defaults to the end of the string.
* @param case_ True for case sensitive, default = true.
* @returns True if the string ends with <find>.
* @example
* 'jumpy'.endsWith('py') -> true
* 'jumpy'.endsWith(/[q-z]/) -> true
* 'jumpy'.endsWith('MPY') -> false
* 'jumpy'.endsWith('MPY', false) -> true
**/
endsWith(find: string, pos?: number, case_?: boolean): boolean;
/**
* @see endsWith
**/
endsWith(find: string, case_?: boolean): boolean;
/**
* @see endsWith
**/
endsWith(find: RegExp, pos?: number, case_?: boolean): boolean;
/**
* @see endsWith
**/
endsWith(find: RegExp, case_?: boolean): boolean;
/**
* Converts HTML characters to their entity equivalents.
* @returns HTML escaped string.
* @example
* '<p>some text</p>'.escapeHTML() -> '<p>some text</p>'
* 'one & two'.escapeHTML() -> 'one & two'
**/
escapeHTML(): string;
/**
* Escapes all RegExp tokens in the string.
* @returns RegExp escaped string.
* @example
* 'really?'.escapeRegExp() -> 'really\?'
* 'yes.'.escapeRegExp() -> 'yes\.'
* '(not really)'.escapeRegExp() -> '\(not really\)'
**/
escapeRegExp(): string;
/**
* Escapes characters in a string to make a valid URL.
* @returns URL escaped string.
* @extra If [param] is true, it will also escape valid URL
* characters for use as a URL parameter.
* @example
* 'http://foo.com/"bar"'.escapeURL() -> 'http://foo.com/%22bar%22'
* 'http://foo.com/"bar"'.escapeURL(true) -> 'http%3A%2F%2Ffoo.com%2F%22bar%22'
**/
escapeURL(param?: boolean): string;
/**
* Returns the first [n] characters of the string.
* @returns String
* @example
* 'lucky charms'.first() -> 'l'
* 'lucky charms'.first(3) -> 'luc'
**/
first(n?: number): string;
/**
* Returns a section of the string starting from [index].
* @returns String
* @example
* 'lucky charms'.from() -> 'lucky charms'
* 'lucky charms'.from(7) -> 'harms'
**/
from(index?: number): string;
/**
* Converts full-width characters (zenkaku) to half-width (hankaku).
* @param mode default = 'all'
* @returns Converted string to hankaku.
* @extra [mode] accepts any combination of
* "a" (alphabet),
* "n" (numbers),
* "k" (katakana),
* "s" (spaces),
* "p" (punctuation),
* or "all".
* @example
* '??? YAMADA??!'.hankaku() -> '??? YAMADA??!'
* '??? YAMADA??!'.hankaku('a') -> '??? YAMADA??!'
* '??? YAMADA??!'.hankaku('alphabet') -> '??? YAMADA??!'
* '?????! 25???!'.hankaku('katakana', 'numbers') -> '?????! 25???!'
* '?????! 25???!'.hankaku('k', 'n') -> '?????! 25???!'
* '?????! 25???!'.hankaku('kn') -> '?????! 25???!'
* '?????! 25???!'.hankaku('sp') -> '?????! 25???!'
**/
hankaku(mode?: string): string;
/**
* @see hankaku
**/
hankaku(...modes: string[]): string;
/**
* Returns true if the string matches <find>.
* @param find Search parameters.
* @returns True if the string matchs <find>, otherwise false.
* @example
* 'jumpy'.has('py') -> true
* 'broken'.has(/[a-n]/) -> true
* 'broken'.has(/[s-z]/) -> false
**/
has(find: string): boolean;
/**
* @see has
**/
has(find: RegExp): boolean;
/**
* Returns true if the string contains any characters in Arabic.
* @returns True if the string contains Arabic.
* @example
* '?????'.hasArabic() -> true
* '?????'.hasCyrillic() -> true
* '? ?????!'.hasHangul() -> true
* '??????'.hasKatakana() -> true
* "l'année".hasLatin() -> true
**/
hasArabic(): boolean;
/**
* Returns true if the string contains any characters in Cyrillic.
* @returns True if the string contains Cyrillic.
**/
hasCyrillic(): boolean;
/**
* Returns true if the string contains any characters in Greek.
* @returns True if the string contains Greek.
**/
hasGreek(): boolean;
/**
* Returns true if the string contains any characters in Hangul.
* @returns True if the string contains Hangul.
**/
hasHangul(): boolean;
/**
* Returns true if the string contains any characters in Han.
* @returns True if the string contains Han.
**/
hasHan(): boolean;
/**
* Returns true if the string contains any characters in Kanji.
* @returns True if the string contains Kanji.
**/
hasKanji(): boolean;
/**
* Returns true if the string contains any characters in Hebrew.
* @returns True if the string contains Hebrew.
**/
hasHebrew(): boolean;
/**
* Returns true if the string contains any characters in Hiragana.
* @returns True if the string contains Hiragana.
**/
hasHiragana(): boolean;
/**
* Returns true if the string contains any characters in Kana.
* @returns True if the string contains Kana.
**/
hasKana(): boolean;
/**
* Returns true if the string contains any characters in Katakana.
* @returns True if the string contains Katakana.
**/
hasKatakana(): boolean;
/**
* Returns true if the string contains any characters in Latin.
* @returns True if the string contains Latin.
**/
hasLatin(): boolean;
/**
* Returns true if the string contains any characters in Thai.
* @returns True if the string contains Thai.
**/
hasThai(): boolean;
/**
* Returns true if the string contains any characters in Devanagari.
* @returns True if the string contains Devanagari.
**/
hasDevanagari(): boolean;
/**
* Converts katakana into hiragana.
* @param all If [all] is false, only full-width katakana will be converted, default = true.
* @returns Converted string to hiragana.
* @example
* '????'.hiragana() -> '????'
* '?????'.hiragana() -> '?????'
* '????'.hiragana() -> '????'
* '????'.hiragana(false) -> '????'
**/
hiragana(all?: boolean): string;
/**
* Creates a human readable string.
* @returns Pretty printed version of the 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(): string;
/**
* Returns true if the string has a length of 0 or contains only whitespace.
* @returns True if the string has a length of 0 or contains only whitespace.
* @example
* ''.isBlank() -> true
* ' '.isBlank() -> true
* 'noway'.isBlank() -> false
**/
isBlank(): boolean;
/**
* Returns true if the string contains only characters in Arabic. Whitespace is ignored.
* @returns True if the string containsly only characters in Arabic.
* @example
* '?????'.isArabic() -> true
* '?????'.isCyrillic() -> true
* '? ?????!'.isHangul() -> true
* '??????'.isKatakana() -> false
* "l'année".isLatin() -> true
**/
isArabic(): boolean;
/**
* Returns true if the string contains only characters in Cyrillic. Whitespace is ignored.
* @returns True if the string containsly only characters in Cyrillic.
**/
isCyrillic(): boolean;
/**
* Returns true if the string contains only characters in Greek. Whitespace is ignored.
* @returns True if the string containsly only characters in Greek.
**/
isGreek(): boolean;
/**
* Returns true if the string contains only characters in Hangul. Whitespace is ignored.
* @returns True if the string containsly only characters in Hangul.
**/
isHangul(): boolean;
/**
* Returns true if the string contains only characters in Han. Whitespace is ignored.
* @returns True if the string containsly only characters in Han.
**/
isHan(): boolean;
/**
* Returns true if the string contains only characters in Kanji. Whitespace is ignored.
* @returns True if the string containsly only characters in Kanji.
**/
isKanji(): boolean;
/**
* Returns true if the string contains only characters in Hebrew. Whitespace is ignored.
* @returns True if the string containsly only characters in Hebrew.
**/
isHebrew(): boolean;
/**
* Returns true if the string contains only characters in Hiragana. Whitespace is ignored.
* @returns True if the string containsly only characters in Hiragana.
**/
isHiragana(): boolean;
/**
* Returns true if the string contains only characters in Kana. Whitespace is ignored.
* @returns True if the string containsly only characters in Kana.
**/
isKana(): boolean;
/**
* Returns true if the string contains only characters in Katakana. Whitespace is ignored.
* @returns True if the string containsly only characters in Katakana.
**/
isKatakana(): boolean;
/**
* Returns true if the string contains only characters in Latin. Whitespace is ignored.
* @returns True if the string containsly only characters in Latin.
**/
isLatin(): boolean;
/**
* Returns true if the string contains only characters in Thai. Whitespace is ignored.
* @returns True if the string containsly only characters in Thai.
**/
isThai(): boolean;
/**
* Returns true if the string contains only characters in Devanagari. Whitespace is ignored.
* @returns True if the string containsly only characters in Devanagari.
**/
isDevanagari(): boolean;
/**
* Converts hiragana into katakana.
* @returns Converted string to katakana.
* @example
* '????'.katakana() -> '????'
* '?????'.katakana() -> '?????'
**/
katakana(): string;
/**
* Returns the last [n] characters of the string.
* @param last Default = 1.
* @returns The last [n] characters of the string.
* @example
* 'lucky charms'.last() -> 's'
* 'lucky charms'.last(3) -> 'rms'
**/
last(n?: number): string;
/**
* Runs callback [fn] against each line in the string.
* @param fn Callback against each line in the original string.
* @returns A string[] where each element is a line in the original string.
* @example
* 'broken wear\nand\njumpy jump'.lines() -> ['broken wear','and','jumpy jump']
* 'broken wear\nand\njumpy jump'.lines(function(l) {
* // Called three times: "broken wear", "and", "jumpy jump"
* });
**/
lines(fn?: (l: string) => void): string[];
/**
* Returns the string with accented and non-standard Latin-based
* characters converted into ASCII approximate equivalents.
* @returns String
* @example
* 'á'.normalize() -> 'a'
* 'Ménage à trois'.normalize() -> 'Menage a trois'
* 'Volkswagen'.normalize() -> 'Volkswagen'
* 'FULLWIDTH'.normalize() -> 'FULLWIDTH'
**/
normalize(): string;
/**
* Pads either/both sides of the string.
* @param padding The padding characters to add to the string.
* @param num The number of <padding> to add to the string, default = 1.
* @returns String
* @extra [num] is the number of characters on each side,
* and [padding] is the character to pad with.
* @example
* 'wasabi'.pad('-') -> '-wasabi-'
* 'wasabi'.pad('-', 2) -> '--wasabi--'
* 'wasabi'.padLeft('-', 2) -> '--wasabi'
* 'wasabi'.padRight('-', 2) -> 'wasabi--'
**/
pad(padding: string, num?: number): string;
/**
* @see pad
**/
padLeft(padding: string, num?: number): string;
/**
* @see pad
**/
padRight(padding: string, num?: number): string;
/**
* Runs callback [fn] against each paragraph in the string.
* @param fn Callback function called for each paragraph in the string.
* @returns Returns a string[] where each element is a paragraph in the original string.
* @extra A paragraph here is defined as a block of text bounded
* by two or more line breaks.
* @example
* 'Once upon a time.\n\nIn the land of oz...'.paragraphs() -> ['Once upon a time.','In the land of oz...']
* 'Once upon a time.\n\nIn the land of oz...'.paragraphs(function(p) {
* // Called twice: "Once upon a time.", "In teh land of oz..."
* });
**/
paragraphs(fn?: (p: string) => void): string[];
/**
* Replaces special characters in a string so that it may be used as part of a pretty URL.
* @returns URL parameterizes the string.
* @example
* 'hell, no!'.parameterize() -> 'hell-no'
**/
parameterize(): string;
/**
* Returns the plural form of the word in the string.
* @method pluralize()
* @returns String
* @example
* 'post'.pluralize() -> 'posts'
* 'octopus'.pluralize() -> 'octopi'
* 'sheep'.pluralize() -> 'sheep'
* 'words'.pluralize() -> 'words'
* 'CamelOctopus'.pluralize() -> 'CamelOctopi'
**/
pluralize(): string;
/**
* Removes any part of the string that matches <find>.
* @param find Remove this from the string.
* @returns String with all instances of <find> removed.
* @extra <find> can be a string or a regex.
* @example
* 'schfifty five'.remove('f') -> 'schity ive'
* 'schfifty five'.remove(/[a-f]/g) -> 'shity iv'
**/
remove(find: string): string;
/**
* @see remove
**/
remove(find: RegExp): string;
/**
* Removes all HTML tags and their contents from the string
* @param tags Remove these HTML tags.
* @returns String with HTML tags removed.
* @extra Tags to remove may be enumerated in the parameters, otherwise will remove all.
* @example
* '<p>just <b>some</b> text</p>'.removeTags() -> ''
* '<p>just <b>some</b> text</p>'.removeTags('b') -> '<p>just text</p>'
**/
removeTags(...tags: string[]): string;
/**
* Returns the string repeated [num] times.
* @param num Number of times to repeat the string, default = 0.
* @returns Repeated [num] string.
* @example
* 'jumpy'.repeat(2) -> 'jumpyjumpy'
* 'a'.repeat(5) -> 'aaaaa'
* 'a'.repeat(0) -> ''
**/
repeat(num?: number): string;
/**
* Reverses the string.
* @returns Reversed string.
* @example
* 'jumpy'.reverse() -> 'ypmuj'
* 'lucky charms'.reverse() -> 'smrahc ykcul'
**/
reverse(): string;
/**
* Shifts each character in the string <num> places in the character map.
* @param num Number of characters to shift in the character map.
* @returns String with characters shifted <num>.
* @example
* 'a'.shift(1) -> 'b'
* '?'.shift(1) -> '?'
**/
shift(num: number): string[];
/**
* The reverse of String#pluralize.
* @returns 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(): string;
/**
* Converts camel case, underscores, and hyphens to a properly spaced string.
* @returns String
* @example
* 'camelCase'.spacify() -> 'camel case'
* 'an-ugly-string'.spacify() -> 'an ugly string'
* 'oh-no_youDid-not'.spacify().capitalize(true) -> 'something else'
**/
spacify(): string;
/**
* Returns true if the string starts with <find>.
* @param find String or RegExp to look for at the beginning of the string.
* @param pos Starting position to start searching, default = 0.
* @param case_ True for case sensitive, default = true.
* @returns True if the string starts with `find`.
* @example
* 'hello'.startsWith('hell') -> true
* 'hello'.startsWith(/[a-h]/) -> true
* 'hello'.startsWith('HELL') -> false
* 'hello'.startsWith('HELL', false) -> true
**/
startsWith(find: string, pos?: number, case_?: boolean): boolean;
/**
* @see startsWith
**/
startsWith(find: string, case_?: boolean): boolean;
/**
* @see startsWith
**/
startsWith(find: RegExp, pos?: number, case_?: boolean): boolean;
/**
* @see startsWith
**/
startsWith(find: RegExp, case_?: boolean): boolean;
/**
* Strips all HTML tags from the string.
* @param tags HTML tags to strip from the string.
* @returns Returns the string with all HTML removed.
* @extra Tags to strip may be enumerated in the parameters, otherwise will strip all.
* @example
* '<p>just <b>some</b> text</p>'.stripTags() -> 'just some text'
* '<p>just <b>some</b> text</p>'.stripTags('p') -> 'just <b>some</b> text'
**/
stripTags(...tags: string[]): string;
/**
* Creates a title version of the string.
* @returns Returns a titlized 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(): string;
/**
* Returns a section of the string ending at [index].
* @param index Ending position in the substring, default = string.length.
* @returns Substring ending at [index].
* @example
* 'lucky charms'.to() -> 'lucky charms'
* 'lucky charms'.to(7) -> 'lucky ch'
**/
to(index?: number): string;
/**
* Converts the string into a number in base [base].
* @param base The base to parse the number in, default = 10.
* @returns Parsed number.
* @extra Any value with a "." fill be converted to a floating point value,
* otherwise an integer.
* @example
* '153'.toNumber() -> 153
* '12,000'.toNumber() -> 12000
* '10px'.toNumber() -> 10
* 'ff'.toNumber(16) -> 255
**/
toNumber(base?: number): number;
/**
* Removes leading and/or trailing whitespace from the string.
* @returns Returns a string with leading and trailing whitespace removed.
* @extra Whitespace is defined as line breaks, tabs, and any character
* in the "Space, Separator" Unicode category, conforming to the
* the ES5 spec. The standard %trim% method is only added when
* not fully supported natively.
* @example
* ' wasabi '.trim() -> 'wasabi'
* ' wasabi '.trimLeft() -> 'wasabi '
* ' wasabi '.trimRight() -> ' wasabi'
**/
// Trim is already available on lib.d.ts interface definition.
//trim(): string;
/**
* Removes leading whitespace from the string.
* @see trim
* @return Returns a string with leading whitespace removed.
**/
trimLeft(): string;
/**
* Removes trailing whitespace from the string.
* @see trim
* @return Returns a string with trailing whitespace removed.
**/
trimRight(): string;
/**
* Truncates a string.
* @param length The length to keep in the string before truncating.
* @param split True to split words, false keeps them intact but may truncate earlier.
* @param from Where to truncate the string from, default = 'right'.
* @param ellipsis Character to use as ellipsis.
* @returns Truncated string.
* @extra If [split] is %false%, will not split words up, and instead
* discard the word where the truncation occurred. [from] can
* also be %"middle"% or %"left"%.
* @example
* 'just sittin on the dock of the bay'.truncate(20) -> 'just sittin on the do...'
* 'just sittin on the dock of the bay'.truncate(20, false) -> 'just sittin on the...'
* 'just sittin on the dock of the bay'.truncate(20, true, 'middle') -> 'just sitt...of the bay'
* 'just sittin on the dock of the bay'.truncate(20, true, 'left') -> '...the dock of the bay'
**/
truncate(length: number, split?: boolean, from?: string, ellipsis?: string): string;
/**
* Converts hyphens and camel casing to underscores.
* @returns Returns a converted string.
* @example
* 'a-farewell-to-arms'.underscore() -> 'a_farewell_to_arms'
* 'capsLock'.underscore() -> 'caps_lock'
* @note Not to be confused with the populate underscore.js library.
**/
underscore(): string;
/**
* Restores escaped HTML characters.
* @returns Returns unescaped HTML string.
* @example
* '<p>some text</p>'.unescapeHTML() -> '<p>some text</p>'
* 'one & two'.unescapeHTML() -> 'one & two'
**/
unescapeHTML(): string;
/**
* Restores escaped characters in a URL escaped string.
* @param partial If true only escape non-valid URL characters, default = false.
* @returns String
* @extra If [partial] is true, it will only unescape non-valid URL characters. [partial] is included here for completeness, but should very rarely be needed.
* @example
* 'http%3A%2F%2Ffoo.com%2Fthe%20bar'.unescapeURL() -> 'http://foo.com/the bar'
* 'http%3A%2F%2Ffoo.com%2Fthe%20bar'.unescapeURL(true) -> 'http%3A%2F%2Ffoo.com%2Fthe bar'
**/
unescapeURL(partial?: boolean): string;
/**
* Runs callback [fn] against each word in the string.
* @param fn Callback to run against each word in the string.
* @returns Returns an string[] with each element containing a word.
* @extra A "word" here is defined as any sequence of non-whitespace characters.
* @example
* 'broken wear'.words() -> ['broken','wear']
* 'broken wear'.words(function(w) {
* // Called twice: "broken", "wear"
* });
**/
words(fn?: (word: string) => void): string[];
/**
* Converts half-width characters (hankaku) to full-width (zenkaku).
* @param modes Types of characters to convert, default = 'all'.
* @returns String
* @extra [mode] accepts any combination of
* "a" (alphabet),
* "n" (numbers),
* "k" (katakana),
* "s" (spaces),
* "p" (punctuation),
* or "all".
* @example
* '??? YAMADA??!'.zenkaku() -> '??? YAMADA??!'
* '??? YAMADA??!'.zenkaku('a') -> '??? YAMADA??!'
* '??? YAMADA??!'.zenkaku('alphabet') -> '??? YAMADA??!'
* '?????! 25???!'.zenkaku('katakana', 'numbers') -> '?????! 25???!'
* '?????! 25???!'.zenkaku('k', 'n') -> '?????! 25???!'
* '?????! 25???!'.zenkaku('kn') -> '?????! 25???!'
* '?????! 25???!'.zenkaku('sp') -> '?????! 25???!'
**/
zenkaku(...modes: string[]): string;
}
// Todo: fix when TypeScript supports adding static functions to native types.
interface NumberStatic {
/**
* Returns a random integer between [n1] and [n2].
* @param n1 Lower bound, default = 0.
* @param n2 Uppder bound, default = 1.
* @returns Random number between [n1] and [n2].
* @extra If only 1 number is passed, the other will be 0. If none are passed, the number will be either 0 or 1.
* @example
* Number.random(50, 100) -> ex. 85
* Number.random(50) -> ex. 27
* Number.random() -> ex. 0
**/
random(n1?: number, n2?: number): number;
}
interface Number {
/**
* Returns an abbreviated form of the number.
* @param precision Rounding precision, default = 0.
* @returns Abbreviated string representation of the number.
* @extra [precision] will round to the given precision.
* @example
* (1000).abbr() -> "1k"
* (1000000).abbr() -> "1m"
* (1280).abbr(1) -> "1.3k"
**/
abbr(precision?: number): string;
/**
* Returns an abbreviated form of the number, considered to be "Bytes".
* @param precision Rounding precision, default = 0.
* @param limit Upper limit for the units, default = 4 which is terabytes.
* @returns Abbreviated string representation of the number in bytes.
* @extra [precision] will round to the given precision.
* [limit] is the upper limit for the units.
* The default is %4%, which is "terabytes" (TB).
* If [limit] is %false%, the upper limit will be "exa".
* @example
* (1000).bytes() -> "1kB"
* (1000).bytes(2) -> "0.98kB"
* ((10).pow(20)).bytes() -> "90,949,470TB"
* ((10).pow(20)).bytes(0, false) -> "87EB"
**/
bytes(precision?: number, limit?: number): string;
/*
* @see bytes
* @limit If false upper limit for units is 'exa'.
**/
bytes(precision?: number, limit?: boolean): string;
/**
* Shortcut for %Math.ceil% that also allows a <precision>.
* @param precision Rounding precision, default = 0.
* @returns Ceiling rounded number.
* @example
* (3.241).ceil() -> 4
* (-3.241).ceil() -> -3
* (3.241).ceil(2) -> 3.25
* (3748).ceil(-2) -> 3800
**/
ceil(precision?: number): number;
/**
* Returns a string at the code point of the number.
* @returns String from character code.
* @example
* (65).chr() -> "A"
* (75).chr() -> "K"
**/
chr(): string;
/**
* Returns an array containing numbers from the number down to <num>.
* @param num Number to count down to.
* @param fn Callback function to call for each number.
* @param step Number to subtract each iteration, default = 1.
* @returns number[] containing numbers from number down to <num>.
* @extra Optionally calls [fn] callback for each number in that array.
* [step] allows multiples greater than 1.
* @example
* (8).downto(3) -> [8, 7, 6, 5, 4, 3]
* (8).downto(3, function(n) {
* // This function is called 6 times receiving n as the value.
* });
* (8).downto(2, null, 2) -> [8, 6, 4, 2]
**/
downto(num: number, fn?: (n: number) => void, step?: number): number[];