├── .gitignore
├── .vscode
├── launch.json
├── settings.json
└── tasks.json
├── .vscodeignore
├── CHANGELOG.md
├── LICENSE.txt
├── README.md
├── extension.ts
├── images
├── MDToolsIcon.svg
├── icon.jpg
└── mdtools1.gif
├── package.json
├── thirdpartynotices.txt
├── tsconfig.json
└── typings
├── underscore.string
└── underscore.string.d.ts
├── underscore
└── underscore.d.ts
└── vscode-typings.d.ts
/.gitignore:
--------------------------------------------------------------------------------
1 | out
2 | node_modules
3 | *.vsix
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | // A launch configuration that compiles the extension and then opens it inside a new window
2 | {
3 | "version": "0.1.0",
4 | "configurations": [
5 | {
6 | "name": "Launch Extension",
7 | "type": "extensionHost",
8 | "runtimeExecutable": "${execPath}",
9 | "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
10 | "stopOnEntry": false,
11 | "sourceMaps": true,
12 | "outDir": "${workspaceRoot}/out",
13 | "preLaunchTask": "npm"
14 | }
15 | ]
16 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | // Place your settings in this file to overwrite default and user settings.
2 | {
3 | "files.exclude": {
4 | "out": false // set this to true to hide the "out" folder with the compiled JS files
5 | },
6 | "typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version
7 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | // Available variables which can be used inside of strings.
2 | // ${workspaceRoot}: the root folder of the team
3 | // ${file}: the current opened file
4 | // ${fileBasename}: the current opened file's basename
5 | // ${fileDirname}: the current opened file's dirname
6 | // ${fileExtname}: the current opened file's extension
7 | // ${cwd}: the current working directory of the spawned process
8 |
9 | // A task runner that calls a custom npm script that compiles the extension.
10 | {
11 | "version": "0.1.0",
12 |
13 | // we want to run npm
14 | "command": "npm",
15 |
16 | // the command is a shell script
17 | "isShellCommand": true,
18 |
19 | // show the output window only if unrecognized errors occur.
20 | "showOutput": "silent",
21 |
22 | // we run the custom script "compile" as defined in package.json
23 | "args": ["run", "compile"],
24 |
25 | // The tsc compiler is started in watching mode
26 | "isWatching": true,
27 |
28 | // use the standard tsc in watch mode problem matcher to find compile problems in the output.
29 | "problemMatcher": "$tsc-watch"
30 | }
--------------------------------------------------------------------------------
/.vscodeignore:
--------------------------------------------------------------------------------
1 | .vscode/**
2 | typings/**
3 | **/*.ts
4 | .gitignore
5 | tsconfig.json
6 | vsc-extension-quickstart.md
7 | *.vsix
8 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Updates
2 |
3 | ## 1.0.1
4 |
5 | * Accepted two PRs thank you [@alefragnani](https://github.com/alefragnani) to fix issues on empty file operations and to support additional filetypes.
6 |
7 | ## 1.0.0
8 |
9 | * Fixed some multi selection bugs
10 | * fix: ASCII Art, toUpper, ToLower all now support multi-selection
11 | * Added in a few more options
12 | * Slugify
13 | * Camelize
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) Microsoft Corporation
2 |
3 | All rights reserved.
4 |
5 | MIT License
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
8 | files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
9 | modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | is furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
16 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
17 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Functionality
2 |
3 | This is an example of how to extend [VS Code](https://github.com/Microsoft/vscode) with some useful text manipulation tools. This extension works for all file types.
4 |
5 | These include:
6 |
7 | * Common casing operations e.g. toUpper, ToLower, SwapCase, Reverse and more
8 | * HTML encoding and Decoding
9 | * ASCII Art
10 |
11 | # Install
12 |
13 | Open up VS Code and hit `F1` and type `ext` select Install Extension and type `mdtools` hit enter and reload window to enable.
14 |
15 | 
16 |
17 |
18 | # Update a selection
19 |
20 | The extension is activated for all file types, and you open up a menu of commands by pressing `Alt+T`. Multi selection is supported for all commands. If you select ASCII Art you will get a secondary menu where you can choose the font.
21 |
22 |
23 | # Known Issues
24 |
25 | Here are a few common issues.
26 |
27 | * The selection zone post edit can be mis-mapped.
28 |
29 |
--------------------------------------------------------------------------------
/extension.ts:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import * as vscode from 'vscode';
4 | import Window = vscode.window;
5 | import QuickPickItem = vscode.QuickPickItem;
6 | import QuickPickOptions = vscode.QuickPickOptions;
7 | import Document = vscode.TextDocument;
8 | import Position = vscode.Position;
9 | import Range = vscode.Range;
10 | import Selection = vscode.Selection;
11 | import TextDocument = vscode.TextDocument;
12 | import TextEditor = vscode.TextEditor;
13 | //import InputBoxOptions = InputBoxOptions;
14 |
15 | var figlet = require('figlet');
16 | import us = require('underscore.string');
17 |
18 | export function activate() {
19 | console.log('Congratulations, your extension "TextTools" is now active!');
20 | vscode.commands.registerCommand('extension.textFunctions', textFunctions);
21 | }
22 |
23 | // String Functions Helper//////////////////////////////
24 | function toUpper(e: TextEditor, d: TextDocument, sel: Selection[]) {
25 | e.edit(function (edit) {
26 | // itterate through the selections and convert all text to Upper
27 | for (var x = 0; x < sel.length; x++) {
28 | let txt: string = d.getText(new Range(sel[x].start, sel[x].end));
29 | edit.replace(sel[x], txt.toUpperCase());
30 | }
31 | });
32 | }
33 |
34 | function toLower(e: TextEditor, d: TextDocument, sel: Selection[]) {
35 | e.edit(function (edit) {
36 | // itterate through the selections and convert all text to Lower
37 | for (var x = 0; x < sel.length; x++) {
38 | let txt: string = d.getText(new Range(sel[x].start, sel[x].end));
39 | edit.replace(sel[x], txt.toLowerCase());
40 | }
41 | });
42 |
43 | }
44 |
45 | // This function takes a callback function for the text formatting 'formatCB',
46 | // if there are any args pass an array as 'argsCB'
47 | function processSelection(e: TextEditor, d: TextDocument, sel: Selection[], formatCB, argsCB) {
48 | var replaceRanges: Selection[] = [];
49 | e.edit(function (edit) {
50 | // itterate through the selections
51 | for (var x = 0; x < sel.length; x++) {
52 | let txt: string = d.getText(new Range(sel[x].start, sel[x].end));
53 | if (argsCB.length > 0) {
54 | // in the case of figlet the params are test to change and font so this is hard coded
55 | // the idea of the array of parameters is to allow for a more general approach in the future
56 | txt = formatCB.apply(this, [txt, argsCB[0]]);
57 | } else {
58 | txt = formatCB(txt);
59 | }
60 |
61 | //replace the txt in the current select and work out any range adjustments
62 | edit.replace(sel[x], txt);
63 | let startPos: Position = new Position(sel[x].start.line, sel[x].start.character);
64 | let endPos: Position = new Position(sel[x].start.line + txt.split(/\r\n|\r|\n/).length - 1, sel[x].start.character + txt.length);
65 | replaceRanges.push(new Selection(startPos, endPos));
66 | }
67 | });
68 | e.selections = replaceRanges;
69 | }
70 |
71 | // Main menu /////////////////////////////////////
72 | function textFunctions() {
73 |
74 | if (!vscode.window.activeTextEditor) {
75 | vscode.window.showInformationMessage('Open a file first to manipulate text selections');
76 | return;
77 | }
78 |
79 | var opts: QuickPickOptions = { matchOnDescription: true, placeHolder: "What do you want to do to the selection(s)?" };
80 | var items: QuickPickItem[] = [];
81 |
82 | items.push({ label: "toUpper", description: "Convert [aBc] to [ABC]" });
83 | items.push({ label: "toLower", description: "Convert [aBc] to [abc]" });
84 | items.push({ label: "swapCase", description: "Convert [aBc] to [AbC]" });
85 | items.push({ label: "Titleize", description: "Convert [hello MD tools] to [Hello MD Tools]" });
86 | items.push({ label: "Camelize", description: "Convert [hello MD-tools] to [HelloMDTools]" });
87 | items.push({ label: "Clean String", description: "Convert [hello......world] to [hello world]" });
88 | items.push({ label: "Reverse", description: "Convert [hello world] to [world hello]" });
89 | items.push({ label: "Escape HTML", description: "Convert [
hello] to [<div>hello]" });
90 | items.push({ label: "UnEscape HTML", description: "Convert [<div>hello] to [
hello]" });
91 | items.push({ label: "Slugify", description: "Convert [txt for an URL] to [txt-for-an-url]" });
92 | items.push({ label: "ASCII Art", description: "Convert [hello] to ASCII Art" });
93 |
94 | Window.showQuickPick(items).then((selection) => {
95 | if (!selection) {
96 | return;
97 | }
98 | let e = Window.activeTextEditor;
99 | let d = e.document;
100 | let sel = e.selections;
101 |
102 | switch (selection.label) {
103 | case "toUpper":
104 | toUpper(e, d, sel);
105 | break;
106 | case "toLower":
107 | toLower(e, d, sel);
108 | break;
109 | case "swapCase":
110 | processSelection(e, d, sel, us.swapCase, []);
111 | break;
112 | case "Titleize":
113 | processSelection(e, d, sel, us.titleize, []);
114 | break;
115 | case "Clean String":
116 | processSelection(e, d, sel, us.clean, []);
117 | break;
118 | case "Reverse":
119 | processSelection(e, d, sel, us.reverse, []);
120 | break;
121 | case "Escape HTML":
122 | processSelection(e, d, sel, us.escapeHTML, []);
123 | break;
124 | case "UnEscape HTML":
125 | processSelection(e, d, sel, us.unescapeHTML, []);
126 | break;
127 | case "Camelize":
128 | processSelection(e, d, sel, us.camelize, []);
129 | break;
130 | case "Slugify":
131 | processSelection(e, d, sel, us.slugify, []);
132 | break;
133 | case "ASCII Art":
134 | // build a full list of the fonts for the drop down
135 | items = [];
136 | figlet.fontsSync().forEach(function (font) {
137 | items.push({ label: font, description: "User the " + font + " font" });
138 | }, this);
139 |
140 | Window.showQuickPick(items).then(function (selection) {
141 | if (!selection) {
142 | return;
143 | }
144 | processSelection(e, d, sel, figlet.textSync, [selection.label]);
145 | });
146 | break;
147 | default:
148 | console.log("hum this should not have happend - no selection")
149 | break;
150 | }
151 | });
152 | }
153 |
--------------------------------------------------------------------------------
/images/MDToolsIcon.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
345 |
--------------------------------------------------------------------------------
/images/icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/vscode-MDTools/1dfb269e85f4edc490c5f7b77f795660e0455f06/images/icon.jpg
--------------------------------------------------------------------------------
/images/mdtools1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/vscode-MDTools/1dfb269e85f4edc490c5f7b77f795660e0455f06/images/mdtools1.gif
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "MDTools",
3 | "description": "Text replacement functions e.g. change case, reverse and ASCII Art for all file types.",
4 | "version": "1.0.1",
5 | "publisher": "seanmcbreen",
6 | "categories":[
7 | "Other"
8 | ],
9 | "license":"SEE LICENSE IN LICENSE.txt",
10 | "icon": "images/MDToolsIcon.svg",
11 | "bugs": {
12 | "url": "https://github.com/Microsoft/vscode-MDTools/issues"
13 | },
14 | "homepage": "https://github.com/Microsoft/vscode-MDTools/blob/master/README.md",
15 | "repository": {
16 | "type": "git",
17 | "url": "https://github.com/Microsoft/vscode-MDTools.git"
18 | },
19 | "galleryBanner" : {
20 | "color": "#5c2d91",
21 | "theme" : "dark"
22 | },
23 | "activationEvents": [
24 | "onCommand:extension.textFunctions"
25 | ],
26 | "engines": {
27 | "vscode": "^1.0.0"
28 | },
29 | "main": "./out/extension",
30 | "contributes": {
31 | "commands": [
32 | {
33 | "command": "extension.textFunctions",
34 | "title": "Text Functions",
35 | "description": "Text functions on selections"
36 | }
37 | ],
38 | "keybindings": [
39 | {
40 | "command": "extension.textFunctions",
41 | "key": "Alt+T"
42 | }
43 | ]
44 | },
45 | "scripts": {
46 | "vscode:prepublish": "node ./node_modules/vscode/bin/compile",
47 | "compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
48 | "postinstall": "node ./node_modules/vscode/bin/install"
49 | },
50 | "dependencies": {
51 | "underscore.string": "^3.2.2",
52 | "figlet": "^1.1.1"
53 | },
54 | "devDependencies": {
55 | "vscode": "^0.11.0",
56 | "typescript": "^1.8.5"
57 | }
58 | }
--------------------------------------------------------------------------------
/thirdpartynotices.txt:
--------------------------------------------------------------------------------
1 | THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
2 | For Microsoft vscode-MDTools
3 |
4 | This project incorporates material from the projects listed below. The original copyright notice
5 | and the license under which Microsoft received such material are set out below. Microsoft reserves
6 | all other rights not expressly granted, whether by implication, estoppel or otherwise.
7 |
8 |
9 | 1. underscore.string version 3.2.2 (https://github.com/epeli/underscore.string)
10 |
11 | The MIT License
12 |
13 | Copyright (c) 2011 Esa-Matti Suuronen esa-matti@suuronen.org
14 |
15 | 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:
16 |
17 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
18 |
19 | 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.
20 |
21 |
22 | 2. figlet 1.1.1 (https://github.com/patorjk/figlet.js)
23 |
24 | The MIT License (MIT)
25 |
26 | Copyright (C) 2014-present Patrick Gillespie and other contributors
27 |
28 | Permission is hereby granted, free of charge, to any person obtaining a copy
29 | of this software and associated documentation files (the "Software"), to deal
30 | in the Software without restriction, including without limitation the rights
31 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32 | copies of the Software, and to permit persons to whom the Software is
33 | furnished to do so, subject to the following conditions:
34 |
35 | The above copyright notice and this permission notice shall be included in
36 | all copies or substantial portions of the Software.
37 |
38 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
44 | THE SOFTWARE.
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "target": "es5",
5 | "outDir": "out",
6 | "noLib": true,
7 | "sourceMap": true,
8 | "rootDir": "."
9 | },
10 | "exclude": [
11 | "node_modules"
12 | ]
13 | }
--------------------------------------------------------------------------------
/typings/underscore.string/underscore.string.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for underscore.string
2 | // Project: https://github.com/epeli/underscore.string
3 | // Definitions by: Ry Racherbaumer
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | ///
7 |
8 | interface UnderscoreStatic {
9 | str: UnderscoreStringStatic;
10 | string: UnderscoreStringStatic;
11 | }
12 |
13 | declare var s : UnderscoreStringStatic;
14 |
15 | interface UnderscoreStringStatic extends UnderscoreStringStaticExports {
16 | /**
17 | * Tests if string contains a substring.
18 | * ('foobar', 'ob') => true
19 | * @param str
20 | * @param needle
21 | */
22 | include(str: string, needle: string): boolean;
23 |
24 | /**
25 | * Tests if string contains a substring.
26 | * ('foobar', 'ob') => true
27 | * @param str
28 | * @param needle
29 | */
30 | contains(str: string, needle: string): boolean;
31 |
32 | /**
33 | * Return reversed string.
34 | * ('foobar') => 'raboof'
35 | * @param str
36 | */
37 | reverse(str: string): string;
38 | }
39 |
40 | /**
41 | * Functions exported for mixing with underscore object.
42 | *
43 | * Usage:
44 | * _.mixin(_.string.exports());
45 | * interface UnderscoreStatic extends UnderscoreStringStaticExports { }
46 | */
47 | interface UnderscoreStringStaticExports {
48 |
49 | exports(): UnderscoreStringStaticExports;
50 |
51 | /**
52 | * Determine if a string is 'blank.'
53 | * @param str
54 | */
55 | isBlank(str: string): boolean;
56 |
57 | /**
58 | * Removes all html tags from string.
59 | * @param str
60 | */
61 | stripTags(str: string): string;
62 |
63 | /**
64 | * Converts first letter of the string to uppercase.
65 | * ('foo Bar') => 'Foo Bar'
66 | * @param str
67 | */
68 | capitalize(str: string): string;
69 |
70 | /**
71 | * Chop a string into pieces.
72 | * ('whitespace', 3) => ['whi','tes','pac','e']
73 | * @param str String to chop
74 | * @param step Size of the pieces
75 | */
76 | chop(str: string, step: number): any[];
77 |
78 | /**
79 | * Compress some whitespaces to one.
80 | * (' foo bar ') => 'foo bar'
81 | * @param str
82 | */
83 | clean(str: string): string;
84 |
85 | /**
86 | * Count occurences of a sub string.
87 | * ('Hello world', 'l') => 3
88 | * @param str
89 | * @param substr
90 | */
91 | count(str: string, substr: string): number;
92 |
93 | /**
94 | * Convert string to an array of characters.
95 | * ('Hello') => ['H','e','l','l','o']
96 | * @param str
97 | */
98 | chars(str: string): any[];
99 |
100 | /**
101 | * Returns a copy of the string in which all the case-based characters have had their case swapped.
102 | * ('hELLO') => 'Hello'
103 | * @param str
104 | */
105 | swapCase(str: string): string;
106 |
107 | /**
108 | * Converts HTML special characters to their entity equivalents.
109 | * ('
'
117 | * @param str
118 | */
119 | unescapeHTML(str: string): string;
120 |
121 | /**
122 | * Escape a string for use in a regular expression.
123 | * @param str
124 | */
125 | escapeRegExp(str: string): string;
126 |
127 | /**
128 | * Splice a string like an array.
129 | * @param str
130 | * @param i
131 | * @param howmany
132 | * @param substr
133 | */
134 | splice(str: string, i: number, howmany: number, substr?: string): string;
135 |
136 | /**
137 | * Insert a string at index.
138 | * @param str
139 | * @param i
140 | * @param substr
141 | */
142 | insert(str: string, i: number, substr: string): string;
143 |
144 | /**
145 | * Joins strings together with given separator.
146 | * (' ', 'foo', 'bar') => 'foo bar'
147 | * @param separator
148 | * @param args
149 | */
150 | join(separator: string, ...args: string[]): string;
151 |
152 | /**
153 | * Split string by newlines character.
154 | * ('Hello\nWorld') => ['Hello', 'World']
155 | * @param str
156 | */
157 | lines(str: string): any[];
158 |
159 | /**
160 | * Checks if string starts with another string.
161 | * ('image.gif', 'image') => true
162 | * @param str
163 | * @param starts
164 | */
165 | startsWith(str: string, starts: string): boolean;
166 |
167 | /**
168 | * Checks if string ends with another string.
169 | * ('image.gif', 'gif') => true
170 | * @param value
171 | * @param starts
172 | */
173 | endsWith(value: string, starts: string): boolean;
174 |
175 | /**
176 | * Returns the successor to passed string.
177 | * ('a') => 'b'
178 | * @param str
179 | */
180 | succ(str: string): string;
181 |
182 | /**
183 | * Capitalize first letter of every word in the string.
184 | * ('my name is epeli') => 'My Name Is Epeli'
185 | * @param str
186 | */
187 | titleize(str: string): string;
188 |
189 | /**
190 | * Converts underscored or dasherized string to a camelized one.
191 | * ('-moz-transform') => 'MozTransform'
192 | * @param str
193 | */
194 | camelize(str: string): string;
195 |
196 | /**
197 | * Converts a camelized or dasherized string into an underscored one.
198 | * ('MozTransform') => 'moz_transform'
199 | * @param str
200 | */
201 | underscored(str: string): string;
202 |
203 | /**
204 | * Converts a underscored or camelized string into an dasherized one.
205 | * ('MozTransform') => '-moz-transform'
206 | * @param str
207 | */
208 | dasherize(str: string): string;
209 |
210 | /**
211 | * Converts string to camelized class name.
212 | * ('some_class_name') => 'SomeClassName'
213 | * @param str
214 | */
215 | classify(str: string): string;
216 |
217 | /**
218 | * Converts an underscored, camelized, or dasherized string into a humanized one.
219 | * Also removes beginning and ending whitespace, and removes the postfix '_id'.
220 | * (' capitalize dash-CamelCase_underscore trim ') => 'Capitalize dash camel case underscore trim'
221 | * @param str
222 | */
223 | humanize(str: string): string;
224 |
225 | /**
226 | * Trims defined characters from begining and ending of the string.
227 | * Defaults to whitespace characters.
228 | * (' foobar ') => 'foobar'
229 | * ('_-foobar-_', '_-') => 'foobar'
230 | * @param str
231 | * @param characters
232 | */
233 | trim(str: string, characters?: string): string;
234 |
235 | /**
236 | * Trims defined characters from begining and ending of the string.
237 | * Defaults to whitespace characters.
238 | * (' foobar ') => 'foobar'
239 | * ('_-foobar-_', '_-') => 'foobar'
240 | * @param str
241 | * @param characters
242 | */
243 | strip(str: string, characters?: string): string;
244 |
245 | /**
246 | * Left trim. Similar to trim, but only for left side.
247 | * @param str
248 | * @param characters
249 | */
250 | ltrim(str: string, characters?: string): string;
251 |
252 | /**
253 | * Left trim. Similar to trim, but only for left side.
254 | * @param str
255 | * @param characters
256 | */
257 | lstrip(str: string, characters?: string): string;
258 |
259 | /**
260 | * Right trim. Similar to trim, but only for right side.
261 | * @param str
262 | * @param characters
263 | */
264 | rtrim(str: string, characters?: string): string;
265 |
266 | /**
267 | * Right trim. Similar to trim, but only for right side.
268 | * @param str
269 | * @param characters
270 | */
271 | rstrip(str: string, characters?: string): string;
272 |
273 | /**
274 | * Truncate string to specified length.
275 | * ('Hello world').truncate(5) => 'Hello...'
276 | * ('Hello').truncate(10) => 'Hello'
277 | * @param str
278 | * @param length
279 | * @param truncateStr
280 | */
281 | truncate(str: string, length: number, truncateStr?: string): string;
282 |
283 | /**
284 | * Elegant version of truncate.
285 | * Makes sure the pruned string does not exceed the original length.
286 | * Avoid half-chopped words when truncating.
287 | * ('Hello, cruel world', 15) => 'Hello, cruel...'
288 | * @param str
289 | * @param length
290 | * @param pruneStr
291 | */
292 | prune(str: string, length: number, pruneStr?: string): string;
293 |
294 | /**
295 | * Split string by delimiter (String or RegExp).
296 | * /\s+/ by default.
297 | * (' I love you ') => ['I','love','you']
298 | * ('I_love_you', '_') => ['I','love','you']
299 | * @param str
300 | * @param delimiter
301 | */
302 | words(str: string): string[];
303 |
304 | /**
305 | * Split string by delimiter (String or RegExp).
306 | * /\s+/ by default.
307 | * (' I love you ') => ['I','love','you']
308 | * ('I_love_you', '_') => ['I','love','you']
309 | * @param str
310 | * @param delimiter
311 | */
312 | words(str: string, delimiter: string): string[];
313 |
314 | /**
315 | * Split string by delimiter (String or RegExp).
316 | * /\s+/ by default.
317 | * (' I love you ') => ['I','love','you']
318 | * ('I_love_you', '_') => ['I','love','you']
319 | * @param str
320 | * @param delimiter
321 | */
322 | words(str: string, delimiter: RegExp): string[];
323 |
324 | /**
325 | * Pads a string with characters until the total string length is equal to the passed length parameter.
326 | * By default, pads on the left with the space char (' ').
327 | * padStr is truncated to a single character if necessary.
328 | * ('1', 8) => ' 1'
329 | * ('1', 8, '0') => '00000001'
330 | * ('1', 8, '0', 'right') => '10000000'
331 | * ('1', 8, '0', 'both') => '00001000'
332 | * ('1', 8, 'bleepblorp', 'both') => 'bbbb1bbb'
333 | * @param str
334 | * @param length
335 | * @param padStr
336 | * @param type
337 | */
338 | pad(str: string, length: number, padStr?:string, type?: string): string;
339 |
340 | /**
341 | * Left-pad a string.
342 | * Alias for pad(str, length, padStr, 'left')
343 | * ('1', 8, '0') => '00000001'
344 | * @param str
345 | * @param length
346 | * @param padStr
347 | */
348 | lpad(str: string, length: number, padStr?: string): string;
349 |
350 | /**
351 | * Left-pad a string.
352 | * Alias for pad(str, length, padStr, 'left')
353 | * ('1', 8, '0') => '00000001'
354 | * @param str
355 | * @param length
356 | * @param padStr
357 | */
358 | rjust(str: string, length: number, padStr?: string): string;
359 |
360 | /**
361 | * Right-pad a string.
362 | * Alias for pad(str, length, padStr, 'right')
363 | * ('1', 8, '0') => '10000000'
364 | * @param str
365 | * @param length
366 | * @param padStr
367 | */
368 | rpad(str: string, length: number, padStr?: string): string;
369 |
370 | /**
371 | * Right-pad a string.
372 | * Alias for pad(str, length, padStr, 'right')
373 | * ('1', 8, '0') => '10000000'
374 | * @param str
375 | * @param length
376 | * @param padStr
377 | */
378 | ljust(str: string, length: number, padStr?: string): string;
379 |
380 | /**
381 | * Left/right-pad a string.
382 | * Alias for pad(str, length, padStr, 'both')
383 | * ('1', 8, '0') => '00001000'
384 | * @param str
385 | * @param length
386 | * @param padStr
387 | */
388 | lrpad(str: string, length: number, padStr?: string): string;
389 |
390 | /**
391 | * Left/right-pad a string.
392 | * Alias for pad(str, length, padStr, 'both')
393 | * ('1', 8, '0') => '00001000'
394 | * @param str
395 | * @param length
396 | * @param padStr
397 | */
398 | center(str: string, length: number, padStr?: string): string;
399 |
400 | /**
401 | * C like string formatting.
402 | * _.sprintf('%.1f', 1.17) => '1.2'
403 | * @param format
404 | * @param args
405 | */
406 | sprintf(format: string, ...args: any[]): string;
407 |
408 | /**
409 | * Parse string to number.
410 | * Returns NaN if string can't be parsed to number.
411 | * ('2.556').toNumber() => 3
412 | * ('2.556').toNumber(1) => 2.6
413 | * @param str
414 | * @param decimals
415 | */
416 | toNumber(str: string, decimals?: number): number;
417 |
418 | /**
419 | * Formats the numbers.
420 | * (1000, 2) => '1,000.00'
421 | * (123456789.123, 5, '.', ',') => '123,456,789.12300'
422 | * @param number
423 | * @param dec
424 | * @param dsep
425 | * @param tsep
426 | */
427 | numberFormat(number: number, dec?: number, dsep?: string, tsep?: string): string;
428 |
429 | /**
430 | * Searches a string from left to right for a pattern.
431 | * Returns a substring consisting of the characters in the string that are to the right of the pattern.
432 | * If no match found, returns entire string.
433 | * ('This_is_a_test_string').strRight('_') => 'is_a_test_string'
434 | * @param str
435 | * @param sep
436 | */
437 | strRight(str: string, sep: string): string;
438 |
439 | /**
440 | * Searches a string from right to left for a pattern.
441 | * Returns a substring consisting of the characters in the string that are to the right of the pattern.
442 | * If no match found, returns entire string.
443 | * ('This_is_a_test_string').strRightBack('_') => 'string'
444 | * @param str
445 | * @param sep
446 | */
447 | strRightBack(str: string, sep: string): string;
448 |
449 | /**
450 | * Searches a string from left to right for a pattern.
451 | * Returns a substring consisting of the characters in the string that are to the left of the pattern.
452 | * If no match found, returns entire string.
453 | * ('This_is_a_test_string').strLeft('_') => 'This'
454 | * @param str
455 | * @param sep
456 | */
457 | strLeft(str: string, sep: string): string;
458 |
459 | /**
460 | * Searches a string from right to left for a pattern.
461 | * Returns a substring consisting of the characters in the string that are to the left of the pattern.
462 | * If no match found, returns entire string.
463 | * ('This_is_a_test_string').strLeftBack('_') => 'This_is_a_test'
464 | * @param str
465 | * @param sep
466 | */
467 | strLeftBack(str: string, sep: string): string;
468 |
469 | /**
470 | * Join an array into a human readable sentence.
471 | * (['jQuery', 'Mootools', 'Prototype']) => 'jQuery, Mootools and Prototype'
472 | * (['jQuery', 'Mootools', 'Prototype'], ', ', ' unt ') => 'jQuery, Mootools unt Prototype'
473 | * @param array
474 | * @param separator
475 | * @param lastSeparator
476 | * @param serial
477 | */
478 | toSentence(array: any[], separator?: string, lastSeparator?: string, serial?: boolean): string;
479 |
480 | /**
481 | * The same as toSentence, but uses ', ' as default for lastSeparator.
482 | * @param array
483 | * @param separator
484 | * @param lastSeparator
485 | */
486 | toSentenceSerial(array: any[], separator?: string, lastSeparator?: string): string;
487 |
488 | /**
489 | * Transform text into a URL slug. Replaces whitespaces, accentuated, and special characters with a dash.
490 | * ('Un éléphant à l'orée du bois') => 'un-elephant-a-loree-du-bois'
491 | * @param str
492 | */
493 | slugify(str: string): string;
494 |
495 | /**
496 | * Surround a string with another string.
497 | * ('foo', 'ab') => 'abfooab'
498 | * @param str
499 | * @param wrapper
500 | */
501 | surround(str: string, wrapper: string): string;
502 |
503 | /**
504 | * Quotes a string.
505 | * quoteChar defaults to "
506 | * ('foo') => '"foo"'
507 | * @param str
508 | */
509 | quote(str: string, quoteChar?: string): string;
510 |
511 | /**
512 | * Quotes a string.
513 | * quoteChar defaults to "
514 | * ('foo') => '"foo"'
515 | * @param str
516 | */
517 | q(str: string, quoteChar?: string): string;
518 |
519 | /**
520 | * Unquotes a string.
521 | * quoteChar defaults to "
522 | * ('"foo"') => 'foo'
523 | * ("'foo'", "'") => 'foo'
524 | * @param str
525 | */
526 | unquote(str: string, quoteChar?: string): string;
527 |
528 | /**
529 | * Repeat a string with an optional separator.
530 | * ('foo', 3) => 'foofoofoo'
531 | * ('foo', 3, 'bar') => 'foobarfoobarfoo'
532 | * @param value
533 | * @param count
534 | * @param separator
535 | */
536 | repeat(value: string, count: number, separator?:string): string;
537 |
538 | /**
539 | * Naturally sort strings like humans would do.
540 | * Caution: this function is charset dependent.
541 | * @param str1
542 | * @param str2
543 | */
544 | naturalCmp(str1: string, str2: string): number;
545 |
546 | /**
547 | * Calculates Levenshtein distance between two strings.
548 | * ('kitten', 'kittah') => 2
549 | * @param str1
550 | * @param str2
551 | */
552 | levenshtein(str1: string, str2: string): number;
553 |
554 | /**
555 | * Turn strings that can be commonly considered as booleans to real booleans.
556 | * Such as "true", "false", "1" and "0". This function is case insensitive.
557 | * ('true') => true
558 | * ('FALSE') => false
559 | * ('random') => undefined
560 | * ('truthy', ['truthy'], ['falsy']) => true
561 | * ('true only at start', [/^true/]) => true
562 | * @param str
563 | * @param trueValues
564 | * @param falseValues
565 | */
566 | toBoolean(str: string, trueValues?: any[], falseValues?: any[]): boolean;
567 |
568 | }
569 | declare module 'underscore.string' {
570 | var underscoreString: UnderscoreStringStatic;
571 | export = underscoreString;
572 | }
573 | // TODO interface UnderscoreString extends Underscore
574 |
--------------------------------------------------------------------------------
/typings/underscore/underscore.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for Underscore 1.7.0
2 | // Project: http://underscorejs.org/
3 | // Definitions by: Boris Yankov , Josh Baldwin
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | declare module _ {
7 | /**
8 | * underscore.js _.throttle options.
9 | **/
10 | interface ThrottleSettings {
11 |
12 | /**
13 | * If you'd like to disable the leading-edge call, pass this as false.
14 | **/
15 | leading?: boolean;
16 |
17 | /**
18 | * If you'd like to disable the execution on the trailing-edge, pass false.
19 | **/
20 | trailing?: boolean;
21 | }
22 |
23 | /**
24 | * underscore.js template settings, set templateSettings or pass as an argument
25 | * to 'template()' to override defaults.
26 | **/
27 | interface TemplateSettings {
28 | /**
29 | * Default value is '/<%([\s\S]+?)%>/g'.
30 | **/
31 | evaluate?: RegExp;
32 |
33 | /**
34 | * Default value is '/<%=([\s\S]+?)%>/g'.
35 | **/
36 | interpolate?: RegExp;
37 |
38 | /**
39 | * Default value is '/<%-([\s\S]+?)%>/g'.
40 | **/
41 | escape?: RegExp;
42 | }
43 |
44 | interface Collection { }
45 |
46 | // Common interface between Arrays and jQuery objects
47 | interface List extends Collection {
48 | [index: number]: T;
49 | length: number;
50 | }
51 |
52 | interface Dictionary extends Collection {
53 | [index: string]: T;
54 | }
55 |
56 | interface ListIterator {
57 | (value: T, index: number, list: List): TResult;
58 | }
59 |
60 | interface ObjectIterator {
61 | (element: T, key: string, list: Dictionary): TResult;
62 | }
63 |
64 | interface MemoIterator {
65 | (prev: TResult, curr: T, index: number, list: List): TResult;
66 | }
67 |
68 | interface MemoObjectIterator {
69 | (prev: TResult, curr: T, key: string, list: Dictionary): TResult;
70 | }
71 | }
72 |
73 | interface UnderscoreStatic {
74 | /**
75 | * Underscore OOP Wrapper, all Underscore functions that take an object
76 | * as the first parameter can be invoked through this function.
77 | * @param key First argument to Underscore object functions.
78 | **/
79 | (value: Array): Underscore;
80 | (value: T): Underscore;
81 |
82 | /* *************
83 | * Collections *
84 | ************* */
85 |
86 | /**
87 | * Iterates over a list of elements, yielding each in turn to an iterator function. The iterator is
88 | * bound to the context object, if one is passed. Each invocation of iterator is called with three
89 | * arguments: (element, index, list). If list is a JavaScript object, iterator's arguments will be
90 | * (value, key, object). Delegates to the native forEach function if it exists.
91 | * @param list Iterates over this list of elements.
92 | * @param iterator Iterator function for each element `list`.
93 | * @param context 'this' object in `iterator`, optional.
94 | **/
95 | each(
96 | list: _.List,
97 | iterator: _.ListIterator,
98 | context?: any): _.List;
99 |
100 | /**
101 | * @see _.each
102 | * @param object Iterates over properties of this object.
103 | * @param iterator Iterator function for each property on `object`.
104 | * @param context 'this' object in `iterator`, optional.
105 | **/
106 | each(
107 | object: _.Dictionary,
108 | iterator: _.ObjectIterator,
109 | context?: any): _.Dictionary;
110 |
111 | /**
112 | * @see _.each
113 | **/
114 | forEach(
115 | list: _.List,
116 | iterator: _.ListIterator,
117 | context?: any): _.List;
118 |
119 | /**
120 | * @see _.each
121 | **/
122 | forEach(
123 | object: _.Dictionary,
124 | iterator: _.ObjectIterator,
125 | context?: any): _.Dictionary;
126 |
127 | /**
128 | * Produces a new array of values by mapping each value in list through a transformation function
129 | * (iterator). If the native map method exists, it will be used instead. If list is a JavaScript
130 | * object, iterator's arguments will be (value, key, object).
131 | * @param list Maps the elements of this array.
132 | * @param iterator Map iterator function for each element in `list`.
133 | * @param context `this` object in `iterator`, optional.
134 | * @return The mapped array result.
135 | **/
136 | map(
137 | list: _.List,
138 | iterator: _.ListIterator,
139 | context?: any): TResult[];
140 |
141 | /**
142 | * @see _.map
143 | * @param object Maps the properties of this object.
144 | * @param iterator Map iterator function for each property on `object`.
145 | * @param context `this` object in `iterator`, optional.
146 | * @return The mapped object result.
147 | **/
148 | map(
149 | object: _.Dictionary,
150 | iterator: _.ObjectIterator,
151 | context?: any): TResult[];
152 |
153 | /**
154 | * @see _.map
155 | **/
156 | collect(
157 | list: _.List,
158 | iterator: _.ListIterator,
159 | context?: any): TResult[];
160 |
161 | /**
162 | * @see _.map
163 | **/
164 | collect(
165 | object: _.Dictionary,
166 | iterator: _.ObjectIterator,
167 | context?: any): TResult[];
168 |
169 | /**
170 | * Also known as inject and foldl, reduce boils down a list of values into a single value.
171 | * Memo is the initial state of the reduction, and each successive step of it should be
172 | * returned by iterator. The iterator is passed four arguments: the memo, then the value
173 | * and index (or key) of the iteration, and finally a reference to the entire list.
174 | * @param list Reduces the elements of this array.
175 | * @param iterator Reduce iterator function for each element in `list`.
176 | * @param memo Initial reduce state.
177 | * @param context `this` object in `iterator`, optional.
178 | * @return Reduced object result.
179 | **/
180 | reduce(
181 | list: _.Collection,
182 | iterator: _.MemoIterator,
183 | memo?: TResult,
184 | context?: any): TResult;
185 |
186 | reduce(
187 | list: _.Dictionary,
188 | iterator: _.MemoObjectIterator,
189 | memo?: TResult,
190 | context?: any): TResult;
191 |
192 | /**
193 | * @see _.reduce
194 | **/
195 | inject(
196 | list: _.Collection,
197 | iterator: _.MemoIterator,
198 | memo?: TResult,
199 | context?: any): TResult;
200 |
201 | /**
202 | * @see _.reduce
203 | **/
204 | foldl(
205 | list: _.Collection,
206 | iterator: _.MemoIterator,
207 | memo?: TResult,
208 | context?: any): TResult;
209 |
210 | /**
211 | * The right-associative version of reduce. Delegates to the JavaScript 1.8 version of
212 | * reduceRight, if it exists. `foldr` is not as useful in JavaScript as it would be in a
213 | * language with lazy evaluation.
214 | * @param list Reduces the elements of this array.
215 | * @param iterator Reduce iterator function for each element in `list`.
216 | * @param memo Initial reduce state.
217 | * @param context `this` object in `iterator`, optional.
218 | * @return Reduced object result.
219 | **/
220 | reduceRight(
221 | list: _.Collection,
222 | iterator: _.MemoIterator,
223 | memo?: TResult,
224 | context?: any): TResult;
225 |
226 | /**
227 | * @see _.reduceRight
228 | **/
229 | foldr(
230 | list: _.Collection,
231 | iterator: _.MemoIterator,
232 | memo?: TResult,
233 | context?: any): TResult;
234 |
235 | /**
236 | * Looks through each value in the list, returning the first one that passes a truth
237 | * test (iterator). The function returns as soon as it finds an acceptable element,
238 | * and doesn't traverse the entire list.
239 | * @param list Searches for a value in this list.
240 | * @param iterator Search iterator function for each element in `list`.
241 | * @param context `this` object in `iterator`, optional.
242 | * @return The first acceptable found element in `list`, if nothing is found undefined/null is returned.
243 | **/
244 | find(
245 | list: _.List,
246 | iterator: _.ListIterator,
247 | context?: any): T;
248 |
249 | /**
250 | * @see _.find
251 | **/
252 | find(
253 | object: _.Dictionary,
254 | iterator: _.ObjectIterator,
255 | context?: any): T;
256 |
257 | /**
258 | * @see _.find
259 | **/
260 | detect(
261 | list: _.List,
262 | iterator: _.ListIterator,
263 | context?: any): T;
264 |
265 | /**
266 | * @see _.find
267 | **/
268 | detect(
269 | object: _.Dictionary,
270 | iterator: _.ObjectIterator,
271 | context?: any): T;
272 |
273 | /**
274 | * Looks through each value in the list, returning the index of the first one that passes a truth
275 | * test (iterator). The function returns as soon as it finds an acceptable element,
276 | * and doesn't traverse the entire list.
277 | * @param list Searches for a value in this list.
278 | * @param iterator Search iterator function for each element in `list`.
279 | * @param context `this` object in `iterator`, optional.
280 | * @return The index of the first acceptable found element in `list`, if nothing is found -1 is returned.
281 | **/
282 | findIndex(
283 | list: _.List,
284 | iterator: _.ListIterator,
285 | context?: any): number;
286 |
287 |
288 | /**
289 | * Looks through each value in the list, returning an array of all the values that pass a truth
290 | * test (iterator). Delegates to the native filter method, if it exists.
291 | * @param list Filter elements out of this list.
292 | * @param iterator Filter iterator function for each element in `list`.
293 | * @param context `this` object in `iterator`, optional.
294 | * @return The filtered list of elements.
295 | **/
296 | filter(
297 | list: _.List,
298 | iterator: _.ListIterator,
299 | context?: any): T[];
300 |
301 | /**
302 | * @see _.filter
303 | **/
304 | filter(
305 | object: _.Dictionary,
306 | iterator: _.ObjectIterator,
307 | context?: any): T[];
308 |
309 | /**
310 | * @see _.filter
311 | **/
312 | select(
313 | list: _.List,
314 | iterator: _.ListIterator,
315 | context?: any): T[];
316 |
317 | /**
318 | * @see _.filter
319 | **/
320 | select(
321 | object: _.Dictionary,
322 | iterator: _.ObjectIterator,
323 | context?: any): T[];
324 |
325 | /**
326 | * Looks through each value in the list, returning an array of all the values that contain all
327 | * of the key-value pairs listed in properties.
328 | * @param list List to match elements again `properties`.
329 | * @param properties The properties to check for on each element within `list`.
330 | * @return The elements within `list` that contain the required `properties`.
331 | **/
332 | where(
333 | list: _.List,
334 | properties: U): T[];
335 |
336 | /**
337 | * Looks through the list and returns the first value that matches all of the key-value pairs listed in properties.
338 | * @param list Search through this list's elements for the first object with all `properties`.
339 | * @param properties Properties to look for on the elements within `list`.
340 | * @return The first element in `list` that has all `properties`.
341 | **/
342 | findWhere(
343 | list: _.List,
344 | properties: U): T;
345 |
346 | /**
347 | * Returns the values in list without the elements that the truth test (iterator) passes.
348 | * The opposite of filter.
349 | * Return all the elements for which a truth test fails.
350 | * @param list Reject elements within this list.
351 | * @param iterator Reject iterator function for each element in `list`.
352 | * @param context `this` object in `iterator`, optional.
353 | * @return The rejected list of elements.
354 | **/
355 | reject(
356 | list: _.List,
357 | iterator: _.ListIterator,
358 | context?: any): T[];
359 |
360 | /**
361 | * @see _.reject
362 | **/
363 | reject(
364 | object: _.Dictionary,
365 | iterator: _.ObjectIterator,
366 | context?: any): T[];
367 |
368 | /**
369 | * Returns true if all of the values in the list pass the iterator truth test. Delegates to the
370 | * native method every, if present.
371 | * @param list Truth test against all elements within this list.
372 | * @param iterator Trust test iterator function for each element in `list`.
373 | * @param context `this` object in `iterator`, optional.
374 | * @return True if all elements passed the truth test, otherwise false.
375 | **/
376 | every(
377 | list: _.List,
378 | iterator?: _.ListIterator,
379 | context?: any): boolean;
380 |
381 | /**
382 | * @see _.every
383 | **/
384 | every(
385 | list: _.Dictionary,
386 | iterator?: _.ObjectIterator,
387 | context?: any): boolean;
388 |
389 | /**
390 | * @see _.every
391 | **/
392 | all(
393 | list: _.List,
394 | iterator?: _.ListIterator,
395 | context?: any): boolean;
396 |
397 | /**
398 | * @see _.every
399 | **/
400 | all(
401 | list: _.Dictionary,
402 | iterator?: _.ObjectIterator,
403 | context?: any): boolean;
404 |
405 | /**
406 | * Returns true if any of the values in the list pass the iterator truth test. Short-circuits and
407 | * stops traversing the list if a true element is found. Delegates to the native method some, if present.
408 | * @param list Truth test against all elements within this list.
409 | * @param iterator Trust test iterator function for each element in `list`.
410 | * @param context `this` object in `iterator`, optional.
411 | * @return True if any elements passed the truth test, otherwise false.
412 | **/
413 | some(
414 | list: _.List,
415 | iterator?: _.ListIterator,
416 | context?: any): boolean;
417 |
418 | /**
419 | * @see _.some
420 | **/
421 | some(
422 | object: _.Dictionary,
423 | iterator?: _.ObjectIterator,
424 | context?: any): boolean;
425 |
426 | /**
427 | * @see _.some
428 | **/
429 | any(
430 | list: _.List,
431 | iterator?: _.ListIterator,
432 | context?: any): boolean;
433 |
434 | /**
435 | * @see _.some
436 | **/
437 | any(
438 | object: _.Dictionary,
439 | iterator?: _.ObjectIterator,
440 | context?: any): boolean;
441 |
442 | /**
443 | * Returns true if the value is present in the list. Uses indexOf internally,
444 | * if list is an Array.
445 | * @param list Checks each element to see if `value` is present.
446 | * @param value The value to check for within `list`.
447 | * @return True if `value` is present in `list`, otherwise false.
448 | **/
449 | contains(
450 | list: _.List,
451 | value: T): boolean;
452 |
453 | /**
454 | * @see _.contains
455 | **/
456 | contains(
457 | object: _.Dictionary,
458 | value: T): boolean;
459 |
460 | /**
461 | * @see _.contains
462 | **/
463 | include(
464 | list: _.Collection,
465 | value: T): boolean;
466 |
467 | /**
468 | * @see _.contains
469 | **/
470 | include(
471 | object: _.Dictionary,
472 | value: T): boolean;
473 |
474 | /**
475 | * Calls the method named by methodName on each value in the list. Any extra arguments passed to
476 | * invoke will be forwarded on to the method invocation.
477 | * @param list The element's in this list will each have the method `methodName` invoked.
478 | * @param methodName The method's name to call on each element within `list`.
479 | * @param arguments Additional arguments to pass to the method `methodName`.
480 | **/
481 | invoke(
482 | list: _.List,
483 | methodName: string,
484 | ...arguments: any[]): any;
485 |
486 | /**
487 | * A convenient version of what is perhaps the most common use-case for map: extracting a list of
488 | * property values.
489 | * @param list The list to pluck elements out of that have the property `propertyName`.
490 | * @param propertyName The property to look for on each element within `list`.
491 | * @return The list of elements within `list` that have the property `propertyName`.
492 | **/
493 | pluck(
494 | list: _.List,
495 | propertyName: string): any[];
496 |
497 | /**
498 | * Returns the maximum value in list.
499 | * @param list Finds the maximum value in this list.
500 | * @return Maximum value in `list`.
501 | **/
502 | max(list: _.List): number;
503 |
504 | /**
505 | * Returns the maximum value in list. If iterator is passed, it will be used on each value to generate
506 | * the criterion by which the value is ranked.
507 | * @param list Finds the maximum value in this list.
508 | * @param iterator Compares each element in `list` to find the maximum value.
509 | * @param context `this` object in `iterator`, optional.
510 | * @return The maximum element within `list`.
511 | **/
512 | max(
513 | list: _.List,
514 | iterator?: _.ListIterator,
515 | context?: any): T;
516 |
517 | /**
518 | * Returns the minimum value in list.
519 | * @param list Finds the minimum value in this list.
520 | * @return Minimum value in `list`.
521 | **/
522 | min(list: _.List): number;
523 |
524 | /**
525 | * Returns the minimum value in list. If iterator is passed, it will be used on each value to generate
526 | * the criterion by which the value is ranked.
527 | * @param list Finds the minimum value in this list.
528 | * @param iterator Compares each element in `list` to find the minimum value.
529 | * @param context `this` object in `iterator`, optional.
530 | * @return The minimum element within `list`.
531 | **/
532 | min(
533 | list: _.List,
534 | iterator?: _.ListIterator,
535 | context?: any): T;
536 |
537 | /**
538 | * Returns a sorted copy of list, ranked in ascending order by the results of running each value
539 | * through iterator. Iterator may also be the string name of the property to sort by (eg. length).
540 | * @param list Sorts this list.
541 | * @param iterator Sort iterator for each element within `list`.
542 | * @param context `this` object in `iterator`, optional.
543 | * @return A sorted copy of `list`.
544 | **/
545 | sortBy(
546 | list: _.List,
547 | iterator?: _.ListIterator,
548 | context?: any): T[];
549 |
550 | /**
551 | * @see _.sortBy
552 | * @param iterator Sort iterator for each element within `list`.
553 | **/
554 | sortBy(
555 | list: _.List,
556 | iterator: string,
557 | context?: any): T[];
558 |
559 | /**
560 | * Splits a collection into sets, grouped by the result of running each value through iterator.
561 | * If iterator is a string instead of a function, groups by the property named by iterator on
562 | * each of the values.
563 | * @param list Groups this list.
564 | * @param iterator Group iterator for each element within `list`, return the key to group the element by.
565 | * @param context `this` object in `iterator`, optional.
566 | * @return An object with the group names as properties where each property contains the grouped elements from `list`.
567 | **/
568 | groupBy(
569 | list: _.List,
570 | iterator?: _.ListIterator,
571 | context?: any): _.Dictionary;
572 |
573 | /**
574 | * @see _.groupBy
575 | * @param iterator Property on each object to group them by.
576 | **/
577 | groupBy(
578 | list: _.List,
579 | iterator: string,
580 | context?: any): _.Dictionary;
581 |
582 | /**
583 | * Given a `list`, and an `iterator` function that returns a key for each element in the list (or a property name),
584 | * returns an object with an index of each item. Just like _.groupBy, but for when you know your keys are unique.
585 | **/
586 | indexBy(
587 | list: _.List,
588 | iterator: _.ListIterator,
589 | context?: any): _.Dictionary;
590 |
591 | /**
592 | * @see _.indexBy
593 | * @param iterator Property on each object to index them by.
594 | **/
595 | indexBy(
596 | list: _.List,
597 | iterator: string,
598 | context?: any): _.Dictionary;
599 |
600 | /**
601 | * Sorts a list into groups and returns a count for the number of objects in each group. Similar
602 | * to groupBy, but instead of returning a list of values, returns a count for the number of values
603 | * in that group.
604 | * @param list Group elements in this list and then count the number of elements in each group.
605 | * @param iterator Group iterator for each element within `list`, return the key to group the element by.
606 | * @param context `this` object in `iterator`, optional.
607 | * @return An object with the group names as properties where each property contains the number of elements in that group.
608 | **/
609 | countBy(
610 | list: _.List,
611 | iterator?: _.ListIterator,
612 | context?: any): _.Dictionary;
613 |
614 | /**
615 | * @see _.countBy
616 | * @param iterator Function name
617 | **/
618 | countBy(
619 | list: _.List,
620 | iterator: string,
621 | context?: any): _.Dictionary;
622 |
623 | /**
624 | * Returns a shuffled copy of the list, using a version of the Fisher-Yates shuffle.
625 | * @param list List to shuffle.
626 | * @return Shuffled copy of `list`.
627 | **/
628 | shuffle(list: _.Collection): T[];
629 |
630 | /**
631 | * Produce a random sample from the `list`. Pass a number to return `n` random elements from the list. Otherwise a single random item will be returned.
632 | * @param list List to sample.
633 | * @return Random sample of `n` elements in `list`.
634 | **/
635 | sample(list: _.Collection, n: number): T[];
636 |
637 | /**
638 | * @see _.sample
639 | **/
640 | sample(list: _.Collection): T;
641 |
642 | /**
643 | * Converts the list (anything that can be iterated over), into a real Array. Useful for transmuting
644 | * the arguments object.
645 | * @param list object to transform into an array.
646 | * @return `list` as an array.
647 | **/
648 | toArray(list: _.Collection): T[];
649 |
650 | /**
651 | * Return the number of values in the list.
652 | * @param list Count the number of values/elements in this list.
653 | * @return Number of values in `list`.
654 | **/
655 | size(list: _.Collection): number;
656 |
657 | /**
658 | * Split array into two arrays:
659 | * one whose elements all satisfy predicate and one whose elements all do not satisfy predicate.
660 | * @param array Array to split in two.
661 | * @param iterator Filter iterator function for each element in `array`.
662 | * @param context `this` object in `iterator`, optional.
663 | * @return Array where Array[0] are the elements in `array` that satisfies the predicate, and Array[1] the elements that did not.
664 | **/
665 | partition(
666 | array: Array,
667 | iterator: _.ListIterator,
668 | context?: any): T[][];
669 |
670 | /*********
671 | * Arrays *
672 | **********/
673 |
674 | /**
675 | * Returns the first element of an array. Passing n will return the first n elements of the array.
676 | * @param array Retrieves the first element of this array.
677 | * @return Returns the first element of `array`.
678 | **/
679 | first(array: _.List): T;
680 |
681 | /**
682 | * @see _.first
683 | * @param n Return more than one element from `array`.
684 | **/
685 | first(
686 | array: _.List,
687 | n: number): T[];
688 |
689 | /**
690 | * @see _.first
691 | **/
692 | head(array: _.List): T;
693 |
694 | /**
695 | * @see _.first
696 | **/
697 | head(
698 | array: _.List,
699 | n: number): T[];
700 |
701 | /**
702 | * @see _.first
703 | **/
704 | take(array: _.List): T;
705 |
706 | /**
707 | * @see _.first
708 | **/
709 | take(
710 | array: _.List,
711 | n: number): T[];
712 |
713 | /**
714 | * Returns everything but the last entry of the array. Especially useful on the arguments object.
715 | * Pass n to exclude the last n elements from the result.
716 | * @param array Retrieve all elements except the last `n`.
717 | * @param n Leaves this many elements behind, optional.
718 | * @return Returns everything but the last `n` elements of `array`.
719 | **/
720 | initial(
721 | array: _.List,
722 | n?: number): T[];
723 |
724 | /**
725 | * Returns the last element of an array. Passing n will return the last n elements of the array.
726 | * @param array Retrieves the last element of this array.
727 | * @return Returns the last element of `array`.
728 | **/
729 | last(array: _.List): T;
730 |
731 | /**
732 | * @see _.last
733 | * @param n Return more than one element from `array`.
734 | **/
735 | last(
736 | array: _.List,
737 | n: number): T[];
738 |
739 | /**
740 | * Returns the rest of the elements in an array. Pass an index to return the values of the array
741 | * from that index onward.
742 | * @param array The array to retrieve all but the first `index` elements.
743 | * @param n The index to start retrieving elements forward from, optional, default = 1.
744 | * @return Returns the elements of `array` from `index` to the end of `array`.
745 | **/
746 | rest(
747 | array: _.List,
748 | n?: number): T[];
749 |
750 | /**
751 | * @see _.rest
752 | **/
753 | tail(
754 | array: _.List,
755 | n?: number): T[];
756 |
757 | /**
758 | * @see _.rest
759 | **/
760 | drop(
761 | array: _.List,
762 | n?: number): T[];
763 |
764 | /**
765 | * Returns a copy of the array with all falsy values removed. In JavaScript, false, null, 0, "",
766 | * undefined and NaN are all falsy.
767 | * @param array Array to compact.
768 | * @return Copy of `array` without false values.
769 | **/
770 | compact(array: _.List): T[];
771 |
772 | /**
773 | * Flattens a nested array (the nesting can be to any depth). If you pass shallow, the array will
774 | * only be flattened a single level.
775 | * @param array The array to flatten.
776 | * @param shallow If true then only flatten one level, optional, default = false.
777 | * @return `array` flattened.
778 | **/
779 | flatten(
780 | array: _.List,
781 | shallow?: boolean): any[];
782 |
783 | /**
784 | * Returns a copy of the array with all instances of the values removed.
785 | * @param array The array to remove `values` from.
786 | * @param values The values to remove from `array`.
787 | * @return Copy of `array` without `values`.
788 | **/
789 | without(
790 | array: _.List,
791 | ...values: T[]): T[];
792 |
793 | /**
794 | * Computes the union of the passed-in arrays: the list of unique items, in order, that are
795 | * present in one or more of the arrays.
796 | * @param arrays Array of arrays to compute the union of.
797 | * @return The union of elements within `arrays`.
798 | **/
799 | union(...arrays: _.List[]): T[];
800 |
801 | /**
802 | * Computes the list of values that are the intersection of all the arrays. Each value in the result
803 | * is present in each of the arrays.
804 | * @param arrays Array of arrays to compute the intersection of.
805 | * @return The intersection of elements within `arrays`.
806 | **/
807 | intersection(...arrays: _.List[]): T[];
808 |
809 | /**
810 | * Similar to without, but returns the values from array that are not present in the other arrays.
811 | * @param array Keeps values that are within `others`.
812 | * @param others The values to keep within `array`.
813 | * @return Copy of `array` with only `others` values.
814 | **/
815 | difference(
816 | array: _.List,
817 | ...others: _.List[]): T[];
818 |
819 | /**
820 | * Produces a duplicate-free version of the array, using === to test object equality. If you know in
821 | * advance that the array is sorted, passing true for isSorted will run a much faster algorithm. If
822 | * you want to compute unique items based on a transformation, pass an iterator function.
823 | * @param array Array to remove duplicates from.
824 | * @param isSorted True if `array` is already sorted, optional, default = false.
825 | * @param iterator Transform the elements of `array` before comparisons for uniqueness.
826 | * @param context 'this' object in `iterator`, optional.
827 | * @return Copy of `array` where all elements are unique.
828 | **/
829 | uniq(
830 | array: _.List,
831 | isSorted?: boolean,
832 | iterator?: _.ListIterator,
833 | context?: any): T[];
834 |
835 | /**
836 | * @see _.uniq
837 | **/
838 | uniq(
839 | array: _.List,
840 | iterator?: _.ListIterator,
841 | context?: any): T[];
842 |
843 | /**
844 | * @see _.uniq
845 | **/
846 | unique(
847 | array: _.List,
848 | iterator?: _.ListIterator,
849 | context?: any): T[];
850 |
851 | /**
852 | * @see _.uniq
853 | **/
854 | unique(
855 | array: _.List,
856 | isSorted?: boolean,
857 | iterator?: _.ListIterator,
858 | context?: any): T[];
859 |
860 |
861 | /**
862 | * Merges together the values of each of the arrays with the values at the corresponding position.
863 | * Useful when you have separate data sources that are coordinated through matching array indexes.
864 | * If you're working with a matrix of nested arrays, zip.apply can transpose the matrix in a similar fashion.
865 | * @param arrays The arrays to merge/zip.
866 | * @return Zipped version of `arrays`.
867 | **/
868 | zip(...arrays: any[][]): any[][];
869 |
870 | /**
871 | * @see _.zip
872 | **/
873 | zip(...arrays: any[]): any[];
874 |
875 | /**
876 | * Converts arrays into objects. Pass either a single list of [key, value] pairs, or a
877 | * list of keys, and a list of values.
878 | * @param keys Key array.
879 | * @param values Value array.
880 | * @return An object containing the `keys` as properties and `values` as the property values.
881 | **/
882 | object(
883 | keys: _.List,
884 | values: _.List): TResult;
885 |
886 | /**
887 | * Converts arrays into objects. Pass either a single list of [key, value] pairs, or a
888 | * list of keys, and a list of values.
889 | * @param keyValuePairs Array of [key, value] pairs.
890 | * @return An object containing the `keys` as properties and `values` as the property values.
891 | **/
892 | object(...keyValuePairs: any[][]): TResult;
893 |
894 | /**
895 | * @see _.object
896 | **/
897 | object(
898 | list: _.List,
899 | values?: any): TResult;
900 |
901 | /**
902 | * Returns the index at which value can be found in the array, or -1 if value is not present in the array.
903 | * Uses the native indexOf function unless it's missing. If you're working with a large array, and you know
904 | * that the array is already sorted, pass true for isSorted to use a faster binary search ... or, pass a number
905 | * as the third argument in order to look for the first matching value in the array after the given index.
906 | * @param array The array to search for the index of `value`.
907 | * @param value The value to search for within `array`.
908 | * @param isSorted True if the array is already sorted, optional, default = false.
909 | * @return The index of `value` within `array`.
910 | **/
911 | indexOf(
912 | array: _.List,
913 | value: T,
914 | isSorted?: boolean): number;
915 |
916 | /**
917 | * @see _indexof
918 | **/
919 | indexOf(
920 | array: _.List,
921 | value: T,
922 | startFrom: number): number;
923 |
924 | /**
925 | * Returns the index of the last occurrence of value in the array, or -1 if value is not present. Uses the
926 | * native lastIndexOf function if possible. Pass fromIndex to start your search at a given index.
927 | * @param array The array to search for the last index of `value`.
928 | * @param value The value to search for within `array`.
929 | * @param from The starting index for the search, optional.
930 | * @return The index of the last occurrence of `value` within `array`.
931 | **/
932 | lastIndexOf(
933 | array: _.List,
934 | value: T,
935 | from?: number): number;
936 |
937 | /**
938 | * Uses a binary search to determine the index at which the value should be inserted into the list in order
939 | * to maintain the list's sorted order. If an iterator is passed, it will be used to compute the sort ranking
940 | * of each value, including the value you pass.
941 | * @param list The sorted list.
942 | * @param value The value to determine its index within `list`.
943 | * @param iterator Iterator to compute the sort ranking of each value, optional.
944 | * @return The index where `value` should be inserted into `list`.
945 | **/
946 | sortedIndex(
947 | list: _.List,
948 | value: T,
949 | iterator?: (x: T) => TSort, context?: any): number;
950 |
951 | /**
952 | * A function to create flexibly-numbered lists of integers, handy for each and map loops. start, if omitted,
953 | * defaults to 0; step defaults to 1. Returns a list of integers from start to stop, incremented (or decremented)
954 | * by step, exclusive.
955 | * @param start Start here.
956 | * @param stop Stop here.
957 | * @param step The number to count up by each iteration, optional, default = 1.
958 | * @return Array of numbers from `start` to `stop` with increments of `step`.
959 | **/
960 |
961 | range(
962 | start: number,
963 | stop: number,
964 | step?: number): number[];
965 |
966 | /**
967 | * @see _.range
968 | * @param stop Stop here.
969 | * @return Array of numbers from 0 to `stop` with increments of 1.
970 | * @note If start is not specified the implementation will never pull the step (step = arguments[2] || 0)
971 | **/
972 | range(stop: number): number[];
973 |
974 | /*************
975 | * Functions *
976 | *************/
977 |
978 | /**
979 | * Bind a function to an object, meaning that whenever the function is called, the value of this will
980 | * be the object. Optionally, bind arguments to the function to pre-fill them, also known as partial application.
981 | * @param func The function to bind `this` to `object`.
982 | * @param context The `this` pointer whenever `fn` is called.
983 | * @param arguments Additional arguments to pass to `fn` when called.
984 | * @return `fn` with `this` bound to `object`.
985 | **/
986 | bind(
987 | func: Function,
988 | context: any,
989 | ...arguments: any[]): () => any;
990 |
991 | /**
992 | * Binds a number of methods on the object, specified by methodNames, to be run in the context of that object
993 | * whenever they are invoked. Very handy for binding functions that are going to be used as event handlers,
994 | * which would otherwise be invoked with a fairly useless this. If no methodNames are provided, all of the
995 | * object's function properties will be bound to it.
996 | * @param object The object to bind the methods `methodName` to.
997 | * @param methodNames The methods to bind to `object`, optional and if not provided all of `object`'s
998 | * methods are bound.
999 | **/
1000 | bindAll(
1001 | object: any,
1002 | ...methodNames: string[]): any;
1003 |
1004 | /**
1005 | * Partially apply a function by filling in any number of its arguments, without changing its dynamic this value.
1006 | * A close cousin of bind. You may pass _ in your list of arguments to specify an argument that should not be
1007 | * pre-filled, but left open to supply at call-time.
1008 | * @param fn Function to partially fill in arguments.
1009 | * @param arguments The partial arguments.
1010 | * @return `fn` with partially filled in arguments.
1011 | **/
1012 | partial(
1013 | fn: Function,
1014 | ...arguments: any[]): Function;
1015 |
1016 | /**
1017 | * Memoizes a given function by caching the computed result. Useful for speeding up slow-running computations.
1018 | * If passed an optional hashFunction, it will be used to compute the hash key for storing the result, based
1019 | * on the arguments to the original function. The default hashFunction just uses the first argument to the
1020 | * memoized function as the key.
1021 | * @param fn Computationally expensive function that will now memoized results.
1022 | * @param hashFn Hash function for storing the result of `fn`.
1023 | * @return Memoized version of `fn`.
1024 | **/
1025 | memoize(
1026 | fn: Function,
1027 | hashFn?: (...args: any[]) => string): Function;
1028 |
1029 | /**
1030 | * Much like setTimeout, invokes function after wait milliseconds. If you pass the optional arguments,
1031 | * they will be forwarded on to the function when it is invoked.
1032 | * @param func Function to delay `waitMS` amount of ms.
1033 | * @param wait The amount of milliseconds to delay `fn`.
1034 | * @arguments Additional arguments to pass to `fn`.
1035 | **/
1036 | delay(
1037 | func: Function,
1038 | wait: number,
1039 | ...arguments: any[]): any;
1040 |
1041 | /**
1042 | * @see _delay
1043 | **/
1044 | delay(
1045 | func: Function,
1046 | ...arguments: any[]): any;
1047 |
1048 | /**
1049 | * Defers invoking the function until the current call stack has cleared, similar to using setTimeout
1050 | * with a delay of 0. Useful for performing expensive computations or HTML rendering in chunks without
1051 | * blocking the UI thread from updating. If you pass the optional arguments, they will be forwarded on
1052 | * to the function when it is invoked.
1053 | * @param fn The function to defer.
1054 | * @param arguments Additional arguments to pass to `fn`.
1055 | **/
1056 | defer(
1057 | fn: Function,
1058 | ...arguments: any[]): void;
1059 |
1060 | /**
1061 | * Creates and returns a new, throttled version of the passed function, that, when invoked repeatedly,
1062 | * will only actually call the original function at most once per every wait milliseconds. Useful for
1063 | * rate-limiting events that occur faster than you can keep up with.
1064 | * By default, throttle will execute the function as soon as you call it for the first time, and,
1065 | * if you call it again any number of times during the wait period, as soon as that period is over.
1066 | * If you'd like to disable the leading-edge call, pass {leading: false}, and if you'd like to disable
1067 | * the execution on the trailing-edge, pass {trailing: false}.
1068 | * @param func Function to throttle `waitMS` ms.
1069 | * @param wait The number of milliseconds to wait before `fn` can be invoked again.
1070 | * @param options Allows for disabling execution of the throttled function on either the leading or trailing edge.
1071 | * @return `fn` with a throttle of `wait`.
1072 | **/
1073 | throttle(
1074 | func: T,
1075 | wait: number,
1076 | options?: _.ThrottleSettings): T;
1077 |
1078 | /**
1079 | * Creates and returns a new debounced version of the passed function that will postpone its execution
1080 | * until after wait milliseconds have elapsed since the last time it was invoked. Useful for implementing
1081 | * behavior that should only happen after the input has stopped arriving. For example: rendering a preview
1082 | * of a Markdown comment, recalculating a layout after the window has stopped being resized, and so on.
1083 | *
1084 | * Pass true for the immediate parameter to cause debounce to trigger the function on the leading instead
1085 | * of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double
1086 | *-clicks on a "submit" button from firing a second time.
1087 | * @param fn Function to debounce `waitMS` ms.
1088 | * @param wait The number of milliseconds to wait before `fn` can be invoked again.
1089 | * @param immediate True if `fn` should be invoked on the leading edge of `waitMS` instead of the trailing edge.
1090 | * @return Debounced version of `fn` that waits `wait` ms when invoked.
1091 | **/
1092 | debounce(
1093 | fn: T,
1094 | wait: number,
1095 | immediate?: boolean): T;
1096 |
1097 | /**
1098 | * Creates a version of the function that can only be called one time. Repeated calls to the modified
1099 | * function will have no effect, returning the value from the original call. Useful for initialization
1100 | * functions, instead of having to set a boolean flag and then check it later.
1101 | * @param fn Function to only execute once.
1102 | * @return Copy of `fn` that can only be invoked once.
1103 | **/
1104 | once(fn: T): T;
1105 |
1106 | /**
1107 | * Creates a version of the function that will only be run after first being called count times. Useful
1108 | * for grouping asynchronous responses, where you want to be sure that all the async calls have finished,
1109 | * before proceeding.
1110 | * @param number count Number of times to be called before actually executing.
1111 | * @param Function fn The function to defer execution `count` times.
1112 | * @return Copy of `fn` that will not execute until it is invoked `count` times.
1113 | **/
1114 | after(
1115 | count: number,
1116 | fn: Function): Function;
1117 |
1118 | /**
1119 | * Creates a version of the function that can be called no more than count times. The result of
1120 | * the last function call is memoized and returned when count has been reached.
1121 | * @param number count The maxmimum number of times the function can be called.
1122 | * @param Function fn The function to limit the number of times it can be called.
1123 | * @return Copy of `fn` that can only be called `count` times.
1124 | **/
1125 | before(
1126 | count: number,
1127 | fn: Function): Function;
1128 |
1129 | /**
1130 | * Wraps the first function inside of the wrapper function, passing it as the first argument. This allows
1131 | * the wrapper to execute code before and after the function runs, adjust the arguments, and execute it
1132 | * conditionally.
1133 | * @param fn Function to wrap.
1134 | * @param wrapper The function that will wrap `fn`.
1135 | * @return Wrapped version of `fn.
1136 | **/
1137 | wrap(
1138 | fn: Function,
1139 | wrapper: (fn: Function, ...args: any[]) => any): Function;
1140 |
1141 | /**
1142 | * Returns a negated version of the pass-in predicate.
1143 | * @param Function predicate
1144 | * @return boolean
1145 | **/
1146 | negate(predicate: Function): boolean;
1147 |
1148 | /**
1149 | * Returns the composition of a list of functions, where each function consumes the return value of the
1150 | * function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())).
1151 | * @param functions List of functions to compose.
1152 | * @return Composition of `functions`.
1153 | **/
1154 | compose(...functions: Function[]): Function;
1155 |
1156 | /**********
1157 | * Objects *
1158 | ***********/
1159 |
1160 | /**
1161 | * Retrieve all the names of the object's properties.
1162 | * @param object Retrieve the key or property names from this object.
1163 | * @return List of all the property names on `object`.
1164 | **/
1165 | keys(object: any): string[];
1166 |
1167 | /**
1168 | * Return all of the values of the object's properties.
1169 | * @param object Retrieve the values of all the properties on this object.
1170 | * @return List of all the values on `object`.
1171 | **/
1172 | values(object: any): any[];
1173 |
1174 | /**
1175 | * Like map, but for objects. Transform the value of each property in turn.
1176 | * @param object The object to transform
1177 | * @param iteratee The function that transforms property values
1178 | * @param context The optional context (value of `this`) to bind to
1179 | * @return a new _.Dictionary of property values
1180 | */
1181 | mapObject(object: _.Dictionary, iteratee: (val: T, key: string, object: _.Dictionary