UNPKG

typescript-closure-tools

Version:

Command-line tools to convert closure-style JSDoc annotations to typescript, and to convert typescript sources to closure externs files

1,822 lines (1,597 loc) 154 kB
// Type definitions for Sugar 1.3.9 // Project: http://sugarjs.com/ // Definitions by: Josh Baldwin <https://github.com/jbaldwin/> // Definitions: https://github.com/borisyankov/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() -> '&lt;p&gt;some text&lt;/p&gt;' * 'one & two'.escapeHTML() -> 'one &amp; 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 * '&lt;p&gt;some text&lt;/p&gt;'.unescapeHTML() -> '<p>some text</p>' * 'one &amp; 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[]; /** * Takes the number as milliseconds and returns a unit-adjusted localized string. * @param locale Locale to convert the ms to, default = currentLocale. * @returns String representation of the duration in [locale]. * @extra This method is the same as %Date#relative% without * the localized equivalent of "from now" or "ago". * [locale] can be passed as the first (and only) parameter. * Note that this method is only available when the dates * package is included. * @example * (500).duration() -> '500 milliseconds' * (1200).duration() -> '1 second' * (75).minutes().duration() -> '1 hour' * (75).minutes().duration('es') -> '1 hora' **/ duration(locale?: string): string; /** * Shortcut for %Math.floor% that also allows a <precision>. * @param precision Rounding precision, default = 0. * @returns Floor rounded number. * @example * (3.241).floor() -> 3 * (-3.841).floor() -> -4 * (3.241).floor(2) -> 3.24 * (3748).floor(-2) -> 3700 **/ floor(precision?: number): number; /** * Formats the number to a readable string. * @method format([place] = 0, [thousands] = ',', [decimal] = '.') * @param place default = 0. * @param thousands Thousands character, default = ','. * @param decimal Decimal character, default = '.'. * @returns String * @extra If [place] is %undefined%, will automatically determine the place. * [thousands] is the character used for the thousands separator. * [decimal] is the character used for the decimal point. * @example * (56782).format() -> '56,782' * (56782).format(2) -> '56,782.00' * (4388.43).format(2, ' ') -> '4 388.43' * (4388.43).format(2, '.', ',') -> '4.388,43' **/ format(place?: number, thousands?: string, decimal?: string): string; /** * Converts the number to hexidecimal. * @method hex([pad] = 1) * @param pad Number of characters to pad. * @returns Hexidecimal number. * @extra [pad] will pad the resulting string to that many places. * @example * (255).hex() -> 'ff'; * (255).hex(4) -> '00ff'; * (23654).hex() -> '5c66'; **/ hex(pad?: number): string; /** * Returns true if the number is even. * @returns True if the number is even, otherwise false. * @example * (6).isEven() -> true * (17).isEven() -> false **/ isEven(): boolean; /** * Returns true if the number has no trailing decimal. * @returns True if the number is an integer, otherwise false. * @example * (420).isInteger() -> true * (4.5).isInteger() -> false **/ isInteger(): boolean; /** * Returns true if the number is a multiple of <num>. * @param num Number to check for multiple of. * @returns True if the number is a multiple of <num>. * @example * (6).isMultipleOf(2) -> true * (17).isMultipleOf(2) -> false * (32).isMultipleOf(4) -> true * (34).isMultipleOf(4) -> false **/ isMultipleOf(num: number): boolean; /** * Returns true if the number is odd. * @returns True if the number is odd, otherwise false. * @example * (3).isOdd() -> true * (18).isOdd() -> false **/ isOdd(): boolean; /** * Returns the logarithm of the number with base <base>, * or natural logarithm of the number if <base> is undefined. * @param base default = Math.E. * @returns Logarithm of the number with base <base>. * @example * (64).log(2) -> 6 * (9).log(3) -> 2 * (5).log() -> 1.6094379124341003 **/ log(base?: number): number; /** * Determines the absolute value of the number. * @returns Absolute value of the number. * @example * (-3).abs() -> 3 **/ abs(): number; /** * sine **/ sin(): number; /** * arcsine **/ asin(): number; /** * cosine **/ cos(): number; /** * arccosine **/ acos(): number; /** * tangent **/ tan(): number; /** * arctangent **/ atan(): number; /** * @example * (1024).sqrt() -> 32 **/ sqrt(): number; /** * E^X **/ exp(): number; /** * n^m * @example * (3).pow(3) -> 27 **/ pow(num: number): number; /*** * Returns the number as a string in metric notation. * @method metric([precision] = 0, [limit] = 1) * @param precision Rounding precision, default = 0. * @param limit Upper limit for the metric units, default = 1 which is kilo. * @returns Metric string notation for the number. * @extra [precision] will round to the given precision. * Both very large numbers and very small numbers are supported. * [limit] is the upper limit for the units. * The default is %1%, which is "kilo". * If [limit] is %false%, the upper limit will be "exa". * The lower limit is "nano", and cannot be changed. * @example * (1000).metric() -> "1k" * (1000000).metric() -> "1,000k" * (1000000).metric(0, false) -> "1M" * (1249).metric(2) + 'g' -> "1.25kg" * (0.025).metric() + 'm' -> "25mm" **/ metric(precision?: number, limit?: number): string; /** * @see metric * @limit If false the upper limit for the metric units will be 'exa'. **/ metric(precision?: number, limit?: boolean): string; /** * Returns an ordinalized (English) string, i.e. "1st", "2nd", etc. * @returns Ordinalized string number equivalent. * @example * (1).ordinalize() -> '1st'; * (2).ordinalize() -> '2nd'; * (8).ordinalize() -> '8th'; **/ ordinalize(): string; /** * Pads a number with "0" to <place>. * @method pad(<place> = 0, [sign] = false, [base] = 10) * @param place Pad up to this many characters, default = 0. * @param sign True to force the sign (+/-), default = false. * @param base The base of the new number, default = 10. * @returns Padded number. * @extra [sign] allows you to force the sign as well (+05, etc). [base] can change the base for numeral conversion. * @example * (5).pad(2) -> '05' * (-5).pad(4) -> '-0005' * (82).pad(3, true) -> '+082' **/ pad(place?: number, sign?: boolean, base?: number): string; /** * Shortcut for %Math.round% that also allows a [precision]. * @param precision Rounding precision, default = 0. * @returns Rounded number to [precision]. * @example * (3.241).round() -> 3 * (-3.841).round() -> -4 * (3.241).round(2) -> 3.24 * (3748).round(-2) -> 3800 **/ round(precision?: number): number; /*** * Calls <fn> a number of times equivalent to the number. * @param fn Callback function to call n times. * @returns The original number. * @example * (8).times(function(i) { * // This function is called 8 times. * }); ***/ times(fn: (i: number) => void): number; /*** * Returns a number. This is mostly for compatibility reasons. * @returns The original number. * @example * (420).toNumber() -> 420 ***/ toNumber(): number; /** * Takes the number as a corresponding unit of time and converts to [unit]. * @method [unit]() * @returns Number * @extra Method names can be both singular and plural. * Note that as "a month" is ambiguous as a unit of time, * %months% will be equivalent to 30.4375 days, the average * number in a month. Be careful using %months% if you need * exact precision. * @set * millisecond * milliseconds * second * seconds * minute * minutes * hour * hours * day * days * week * weeks * month * months * year * years * @example * (5).milliseconds() -> 5 * (10).hours() -> 36000000 * (1).day() -> 86400000 **/ millisecond(): number; /** * @see millisecond **/ milliseconds(): number; /** * @see millisecond **/ second(): number; /** * @see millisecond **/ seconds(): number; /** * @see millisecond **/ minute(): number; /** * @see millisecond **/ minutes(): number; /** * @see millisecond **/ hour(): number; /** * @see millisecond **/ hours(): number; /** * @see millisecond **/ day(): number; /** * @see millisecond **/ days(): number; /** * @see millisecond **/ week(): number; /** * @see millisecond **/ weeks(): number; /** * @see millisecond **/ month(): number; /** * @see millisecond **/ months(): number; /** * @see millisecond **/ year(): number; /** * @see millisecond **/ years(): number; /** * Returns a date <n> units after <d>, where <n> is the number. * @method [unit]After([d], [locale] = currentLocale) * @param d Date to start from. * @param locale Locale for return Date, default = currentLocale. * @returns Date <n> units after <d>. * @extra [d] will accept a date object, timestamp, or text format. * Note that "months" is ambiguous as a unit of time. If the * target date falls on a day that does not exist * (ie. August 31 -> February 31), the date will be shifted * to the last day of the month. Be careful using %monthsAfter% * if you need exact precision. See @date_format for more. * @set * millisecondAfter * millisecondsAfter * secondAfter * secondsAfter * minuteAfter * minutesAfter * hourAfter * hoursAfter * dayAfter * daysAfter * weekAfter * weeksAfter * monthAfter * monthsAfter * yearAfter * yearsAfter * @example * (5).daysAfter('tuesday') -> 5 days after tuesday of this week * (1).yearAfter('January 23, 1997') -> January 23, 1998 **/ millisecondAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ millisecondAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ millisecondsAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ millisecondsAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ secondAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ secondAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ secondsAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ secondsAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ minuteAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ minuteAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ minutesAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ minutesAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ hourAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ hourAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ hoursAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ hoursAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ dayAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ dayAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ daysAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ daysAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ weekAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ weekAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ weeksAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ weeksAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ monthAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ monthAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ monthsAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ yearAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ yearAfter(d: Date, locale?: string): Date; /** * @see millisecondAfter **/ yearsAfter(d: string, locale?: string): Date; /** * @see millisecondAfter **/ yearsAfter(d: Date, locale?: string): Date; /** * Returns a date that is <n> units ago. * @method [unit]Ago() * @returns Date * @extra Note that "months" is ambiguous as a unit of time. * If the target date falls on a day that does not exist * (ie. August 31 -> February 31), the date will be shifted * to the last day of the month. Be careful using %monthsAgo% * if you need exact precision. * @set * millisecondAgo * millisecondsAgo * secondAgo * secondsAgo * minuteAgo * minutesAgo * hourAgo * hoursAgo * dayAgo * daysAgo * weekAgo * weeksAgo * monthAgo * monthsAgo * yearAgo * yearsAgo * @example * (5).weeksAgo() -> 5 weeks ago * (1).yearAgo() -> January 23, 1996 **/ millisecondAgo(): Date; /** * @see millisecondAgo **/ millisecondsAgo(): Date; /** * @see millisecondAgo **/ secondAgo(): Date; /** * @see millisecondAgo **/ secondsAgo(): Date; /** * @see millisecondAgo **/ minuteAgo(): Date; /** * @see millisecondAgo **/ minutesAgo(): Date; /** * @see millisecondAgo **/ hourAgo(): Date; /** * @see millisecondAgo **/ hoursAgo(): Date; /** * @see millisecondAgo **/ dayAgo(): Date; /** * @see millisecondAgo **/ daysAgo(): Date; /** * @see millisecondAgo **/ weekAgo(): Date; /** * @see millisecondAgo **/ weeksAgo(): Date; /** * @see millisecondAgo **/ monthAgo(): Date; /** * @see millisecondAgo **/ monthsAgo(): Date; /** * @see millisecondAgo **/ yearAgo(): Date; /** * @see millisecondAgo **/ yearsAgo(): Date; /** * Returns a date that is <n> units before <d>, where <n> is the number. * @method [unit]Before([d], [locale] = currentLocale) * @param d Date to start from. * @param locale Locale for return Date, default = currentLocale. * @returns Date <n> units before <d>. * @extra [d] will accept a date object, timestamp, or text format. * Note that "months" is ambiguous as a unit of time. If the * target date falls on a day that does not exist * (ie. August 31 -> February 31), the date will be shifted to * the last day of the month. Be careful using %monthsBefore% * if you need exact precision. See @date_format for more. * @set * millisecondBefore * millisecondsBefore * secondBefore * secondsBefore * minuteBefore * minutesBefore * hourBefore * hoursBefore * dayBefore * daysBefore * weekBefore * weeksBefore * monthBefore * monthsBefore * yearBefore * yearsBefore * @example * (5).daysBefore('tuesday') -> 5 days before tuesday of this week * (1).yearBefore('January 23, 1997') -> January 23, 1996 **/ millisecondBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ millisecondBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ millisecondsBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ millisecondsBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ secondBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ secondBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ secondsBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ secondsBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ minuteBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ minuteBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ minutesBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ minutesBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ hourBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ hourBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ hoursBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ hoursBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ dayBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ dayBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ daysBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ daysBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ weekBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ weekBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ weeksBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ weeksBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ monthBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ monthBefore(d: Date, locale?: string): Date; /** * @see millisecondBefore **/ monthsBefore(d: string, locale?: string): Date; /** * @see millisecondBefore **/ monthsBefore(d: Date, locale?: string): Date; /** * @