Coverage

99%
481
478
3

lib/array.js

100%
55
55
0
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/**
7 * @module array
8 */
9
10/**
11 * Slice the array by one element
12 *
13 * @param {Array} array
14 * @return {Array}
15 */
161var slice1 = function slice1(array) {
173 return Array.prototype.slice.call(array, 1);
18};
19
201exports.slice1 = slice1;
21/**
22 * Search if the array has an element.
23 * Shortcut for indexOf !== -1
24 *
25 * @param {Array} array
26 * @param {*} searchElement
27 * @param {Number} i
28 * @return {Boolean}
29 */
301var has = function has(array, searchElement, i) {
312 return Array.prototype.indexOf.call(array, searchElement, i) !== -1;
32};
33
341exports.has = has;
35/**
36 * Search if the array has an element among provided elements.
37 * Shortcut for indexOf !== -1
38 *
39 * @param {Array} array
40 * @param {Array} searchElements
41 * @param {Number} i
42 * @return {Boolean}
43 */
441var hasAmong = function hasAmong(array, searchElements, i) {
45 for (var j = 0, l = searchElements.length; j < l; j++) {
46 if (Array.prototype.indexOf.call(array, searchElements[j], i) !== -1) {
474 return true;
48 }
49 }
502 return false;
51};
52
531exports.hasAmong = hasAmong;
54/**
55 * Remove an element in an array
56 *
57 * @param {Array} array
58 * @param {*} element
59 * @return {Boolean}
60 */
611var remove = function remove(array, element) {
624 var index = array.indexOf(element);
63 if (index === -1) {
641 return false;
65 }
66
673 array.splice(index, 1);
683 return index;
69};
70
711exports.remove = remove;
72/**
73 * Clone an array
74 *
75 * @param {Array} array
76 * @return {Array} cloned array
77 */
781var clone = function clone(array) {
791 return array.slice(0);
80};
81
821exports.clone = clone;
83/**
84 * Last element in an array
85 *
86 * @param {Array} array
87 * @return {*} last element
88 */
891var last = function last(array) {
902 return array[array.length - 1];
91};
92
931exports.last = last;
94/**
95 * Random element in an array
96 *
97 * @param {Array} array
98 * @return {*} last element
99 */
1001var random = function random(array) {
1011 return array[Math.floor(Math.random() * array.length)];
102};
103
1041exports.random = random;
105/**
106 * Sort functions
107 *
108 * @type {Object}
109 */
1101var sortFunctions = {
111 "": function (a, b) {
112 if (a < b) {
1131 return -1;
114 }
115 if (a > b) {
1161 return 1;
117 }
1181 return 0;
119 },
120 number: function number(a, b) {
12122 return a - b;
122 },
123 string: function string(a, b) {
1245 return a.localeCompare(b);
125 }
126};
127
1281exports.sortFunctions = sortFunctions;
1291var sortF = sortFunctions;
130
1311exports.sortF = sortF;
132/**
133 * Sorts an array by a property
134 *
135 * @param {Array} array
136 * @param {String} propertyName
137 * @param {?Boolean} descending
138 * @param {Function|String|undefined} sortFunction
139 * @return {Array}
140 */
1411var sortBy = function sortBy(array, propertyName, descending, sortFunction) {
142 if (typeof descending === "string" || typeof descending === "function") {
1434 sortFunction = descending;
1444 descending = undefined;
145 }
146
147 if (typeof sortFunction !== "function") {
1488 sortFunction = sortFunctions[sortFunction == null ? "" : sortFunction];
149 }
150
1518 return array.sort(descending ? function (b, a) {
1524 return sortFunction(a[propertyName], b[propertyName]);
153 } : function (a, b) {
15426 return sortFunction(a[propertyName], b[propertyName]);
155 });
156};
157
1581exports.sortBy = sortBy;
159/* findBy: use Array.prototype.find((v) => v.propertyName === value); */
160/* findIndexBy: use Array.prototype.findIndex((v) => v.propertyName === value); */
161
162/**
163 * The removeWhen() method removes elements
164 * when element pass the test implemented by the provided function.
165 *
166 * @param {Array} array
167 * @param {Function} callback
168 * @return {Number} the new array's length
169 */
1701var removeWhen = function removeWhen(array, callback) {
1711 array.forEach(function (elt, index) {
172 if (callback(elt, index)) {
1732 array.splice(index, 1);
174 }
175 });
1761 return array.length;
177};
178
1791exports.removeWhen = removeWhen;
180/**
181 * Tests if an array equals another
182 *
183 * @param {Array} array1
184 * @param {Array} array2
185 * @return {Boolean}
186 */
1871var equals = function equals(array1, array2) {
1885 var length = array1.length;
189 if (!Array.isArray(array1) || !Array.isArray(array2) || length != array2.length) {
1901 return false;
191 }
192 for (var i = 0; i < length; i++) {
193 if (array1[i] !== array2[i]) {
1942 return false;
195 }
196 }
1972 return true;
198};
1991exports.equals = equals;
200//# sourceMappingURL=array.js.map

lib/date.js

100%
24
24
0
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/**
7 * @module date
8 */
9
10/**
11 * Returns if the year in parameter is a leap year
12 *
13 * @param {Number} year
14 * @return {Boolean}
15 */
161var isLeapYear = function isLeapYear(year) {
177 return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0 || year === 0;
18};
19
201exports.isLeapYear = isLeapYear;
211var _daysInMonth = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
22/**
23 * Returns the number of days in the month and year in parameters
24 *
25 * @param {Number} month from 0 to 11
26 * @param {Number} year
27 * @return {Number} 28, 29, 30 or 31
28 */
291var daysInMonth = function daysInMonth(month, year) {
30 if (month === 1) {
312 return exports.isLeapYear(year) ? 29 : 28;
32 }
3311 return _daysInMonth[month];
34};
35
361exports.daysInMonth = daysInMonth;
37/**
38 * Transform a date into a SQL date : YYYY-MM-DD HH:MM:SS
39 *
40 * @param {Date} date
41 * @param {Boolean} withHours
42 * @return {String} string date with format YYYY-MM-DD HH:MM:SS
43 */
441var toSqlDate = function toSqlDate(date, withHours) {
454 var day = date.getDate(),
46 month = date.getMonth();
474 var result = date.getFullYear() + "-" + (month < 9 ? "0" : "") + (month + 1) + "-" + (day < 10 ? "0" : "") + day;
48 if (withHours === false) {
492 return result;
50 }
512 var hours = date.getHours(),
52 minutes = date.getMinutes(),
53 seconds = date.getSeconds();
542 return result + " " + (hours < 10 ? "0" : "") + hours + (minutes < 10 ? ":0" : ":") + minutes + (seconds < 10 ? ":0" : ":") + seconds;
55};
56
571exports.toSqlDate = toSqlDate;
58/**
59 * Transform a SQL string date into a Date
60 *
61 * @param {String} sqlDate
62 * @return {Date} date
63 */
641var parseSqlDate = function parseSqlDate(date) {
654 date = date.split(" ");
664 date[0] = date[0].split("-");
67 if (date.length === 2) {
682 date[1] = date[1].split(":");
692 return new Date(date[0][0], date[0][1] - 1, date[0][2], date[1][0], date[1][1], date[1][2]);
70 }
712 return new Date(date[0][0], date[0][1] - 1, date[0][2]);
72};
731exports.parseSqlDate = parseSqlDate;
74//# sourceMappingURL=date.js.map

lib/fs.js

100%
60
60
0
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/* jshint maxlen: 200 */
7/**
8 * fs API with Promises
9 *
10 * @module fs
11 */
12
131var fs = require("fs");
141var promisesUtils = require("./promises");
151var YAML = require("js-yaml");
16
17/**
18 * Rename a file synchronously
19 *
20 * @param {String} oldPath
21 * @param {String} newPath
22 * @return {Boolean}
23 */
24
251[
26/**
27 * Rename a file
28 *
29 * @function module:fs.rename
30 * @param {String} oldPath
31 * @param {String} newPath
32 * @return {Promise}
33 */
34"rename",
35/**
36 * Truncate a file to a specified length
37 *
38 * @function module:fs.ftruncate
39 * @param {FileDescriptor} fd file descriptor
40 * @param {Number=} len
41 * @return {Promise}
42 */
43"ftruncate",
44/**
45 * Truncate a file to a specified length
46 *
47 * @function module:fs.truncate
48 * @param {String} path
49 * @param {Number=} len
50 * @return {Promise}
51 */
52"truncate",
53/**
54 * Change ownership of a file
55 *
56 * @function module:fs.chown
57 * @param {String} path
58 * @param {Number=} len
59 * @return {Promise}
60 */
61"chown",
62/**
63 * Change ownership of a file
64 *
65 * @function module:fs.fchown
66 * @param {FileDescriptor} fd file descriptor
67 * @param {Number=} len
68 * @return {Promise}
69 */
70"fchown",
71/**
72 * Change ownership of a file
73 * is like chown(), but does not dereference symbolic links.
74 *
75 * @function module:fs.lchown
76 * @param {String} path
77 * @param {Number=} len
78 * @return {Promise}
79 */
80"lchown",
81/**
82 * Change permissions of a file
83 *
84 * Changes the permissions of the file specified whose pathname is given in path,
85 * which is dereferenced if it is a symbolic link.
86 *
87 * @function module:fs.chmod
88 * @param {String} path
89 * @param {Number=} len
90 * @return {Promise}
91 */
92"chmod",
93/**
94 * Change permissions of a file
95 *
96 * @function module:fs.fchmod
97 * @param {FileDescriptor} fd file descriptor
98 * @param {Number=} len
99 * @return {Promise}
100 */
101"fchmod",
102/**
103 * Change permissions of a file
104 *
105 * @function module:fs.lchmod
106 * @param {String} path
107 * @param {Number=} len
108 * @return {Promise}
109 */
110"lchmod",
111/**
112 * Get file status
113 *
114 * @function module:fs.stat
115 * @param {String} path
116 * @param {Number=} len
117 * @return {Promise}
118 */
119"stat",
120/**
121 * Get file status
122 *
123 * Identical to stat(), except that if path is a symbolic link,
124 * then the link itself is stat-ed, not the file that it refers to.
125 *
126 * @function module:fs.lstat
127 * @param {String} path
128 * @param {Number=} len
129 * @return {Promise}
130 */
131"lstat",
132/**
133 * Get file status
134 *
135 * @function module:fs.fstat
136 * @param {FileDescriptor} fd file descriptor
137 * @param {Number=} len
138 * @return {Promise}
139 */
140"fstat",
141/**
142 * Make a new name for a file
143 *
144 * link() creates a new link (also known as a hard link) to an existing file.
145 *
146 * @function module:fs.stat
147 * @param {FileDescriptor} fd file descriptor
148 * @param {Number=} len
149 * @return {Promise}
150 */
151"link",
152/**
153 * Make a new name for a file
154 *
155 * symlink() creates a symbolic link named newpath which contains the string oldpath.
156 *
157 * @function module:fs.symlink
158 * @param {String} oldPath
159 * @param {String} newPath
160 * @return {Promise}
161 */
162"symlink",
163/**
164 * Read value of a symbolic link
165 *
166 * readlink() places the contents of the symbolic link path in the buffer buf,
167 * which has size bufsiz. readlink() does not append a null byte to buf.
168 * It will truncate the contents (to a length of bufsiz characters),
169 * in case the buffer is too small to hold all of the contents.
170 *
171 * @function module:fs.readlink
172 * @param {String} path
173 * @return {Promise}
174 */
175"readlink",
176/**
177 * The callback gets two arguments (err, resolvedPath).
178 *
179 * May use process.cwd to resolve relative paths. cache is an object literal of mapped paths
180 * that can be used to force a specific path resolution or avoid additional fs.stat calls for known real paths.
181 *
182 * @example
183 * var cache = {'/etc':'/private/etc'};
184 * fs.realpath('/etc/passwd', cache).then(function(resolvedPath) {
185 * console.log(resolvedPath);
186 * });
187 *
188 * @function module:fs.realpath
189 * @param {String} path
190 * @return {Promise}
191 */
192"realpath",
193/**
194 * Delete a name and possibly the file it refers to
195 *
196 * unlink() deletes a name from the file system.
197 *
198 * If that name was the last link to a file and no processes have the file open
199 * the file is deleted and the space it was using is made available for reuse.
200 *
201 * If the name was the last link to a file but any processes still have the file open
202 * the file will remain in existence until the last file descriptor referring to it is closed.
203 *
204 * If the name referred to a symbolic link the link is removed.
205 *
206 * If the name referred to a socket, fifo or device the name for it is removed
207 * but processes which have the object open may continue to use it.
208 *
209 * @function module:fs.unlink
210 * @param {String} path
211 * @return {Promise}
212 */
213"unlink",
214/**
215 * Delete a directory
216 *
217 * rmdir() deletes a directory, which must be empty.
218 *
219 * @function module:fs.rmdir
220 * @param {String} path
221 * @return {Promise}
222 */
223"rmdir",
224/**
225 * Create a directory
226 *
227 * rmdir() deletes a directory, which must be empty.
228 *
229 * mkdir() attempts to create a directory named path.
230 *
231 * The argument mode specifies the permissions to use.
232 * It is modified by the process's umask in the usual way:
233 * the permissions of the created directory are (mode & ~umask & 0777).
234 * Other mode bits of the created directory depend on the operating system. For Linux, see below.
235 *
236 * @function module:fs.mkdir
237 * @param {String} path
238 * @param {String|Number=} mode
239 * @return {Promise}
240 */
241"mkdir",
242/**
243 * Reads the contents of a directory.
244 * Promise's result where files is an array of the names of the files in the directory excluding '.' and '..'.
245 *
246 * @function module:fs.readdir
247 * @param {String} path
248 * @return {Promise}
249 */
250"readdir",
251/**
252 * No arguments other than a possible exception are given to the completion callback.
253 *
254 * @function module:fs.close
255 * @param {String} path
256 * @return {Promise}
257 */
258"close",
259/**
260 * No arguments other than a possible exception are given to the completion callback.
261 *
262 * 'r' - Open file for reading. An exception occurs if the file does not exist.
263 * 'r+' - Open file for reading and writing. An exception occurs if the file does not exist.
264 * 'rs' - Open file for reading in synchronous mode.
265 * Instructs the operating system to bypass the local file system cache.
266 * This is primarily useful for opening files on NFS mounts
267 * as it allows you to skip the potentially stale local cache.
268 * It has a very real impact on I/O performance so don't use this flag unless you need it.
269 * 'rs+' - Open file for reading and writing, telling the OS to open it synchronously.
270 * See notes for 'rs' about using this with caution.
271 * 'w' - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
272 * 'wx' - Like 'w' but fails if path exists.
273 * 'w+' - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
274 * 'wx+' - Like 'w+' but fails if path exists.
275 * 'a' - Open file for appending. The file is created if it does not exist.
276 * 'ax' - Like 'a' but fails if path exists.
277 * 'a+' - Open file for reading and appending. The file is created if it does not exist.
278 * 'ax+' - Like 'a+' but fails if path exists.
279 *
280 * mode sets the file mode (permission and sticky bits), but only if the file was created.
281 * It defaults to 0666, readable and writeable.
282 *
283 * The exclusive flag 'x' (O_EXCL flag in open(2)) ensures that path is newly created.
284 * On POSIX systems, path is considered to exist even if it is a symlink to a non-existent file.
285 * The exclusive flag may or may not work with network file systems.
286 *
287 * On Linux, positional writes don't work when the file is opened in append mode.
288 * The kernel ignores the position argument and always appends the data to the end of the file.
289 *
290 * @function module:fs.close
291 * @param {String} path
292 * @param {String} flags
293 * @param {String|Number=} mode
294 * @return {Promise}
295 */
296"open",
297/**
298 * Change file last access and modification times
299 *
300 * The utime() system call changes the access and modification times of the inode specified by filename
301 * to the actime and modtime fields of times respectively.
302 *
303 * If times is NULL, then the access and modification times of the file are set to the current time.
304 *
305 * Changing timestamps is permitted when: either the process has appropriate privileges,
306 * or the effective user ID equals the user ID of the file,
307 * or times is NULL and the process has write permission for the file.
308 *
309 * @function module:fs.utimes
310 * @param {String} path
311 * @param {String} atime
312 * @param {String} mtime
313 * @return {Promise}
314 */
315"utimes",
316/**
317 * Change file last access and modification times
318 *
319 * The utime() system call changes the access and modification times of the inode specified by filename
320 * to the actime and modtime fields of times respectively.
321 *
322 * If times is NULL, then the access and modification times of the file are set to the current time.
323 *
324 * Changing timestamps is permitted when: either the process has appropriate privileges,
325 * or the effective user ID equals the user ID of the file,
326 * or times is NULL and the process has write permission for the file.
327 *
328 * @function module:fs.futimes
329 * @param {FileDescriptor} fd file descriptor
330 * @param {String} atime
331 * @param {String} mtime
332 * @return {Promise}
333 */
334"futimes",
335/**
336 * Synchronize a file's in-core state with storage device
337 *
338 * @function module:fs.fsync
339 * @param {FileDescriptor} fd file descriptor
340 * @return {Promise}
341 */
342"fsync",
343/**
344 * Write buffer to the file specified by fd.
345 *
346 * @function module:fs.write
347 * @param {FileDescriptor} fd file descriptor
348 * @param {*} buffer
349 * @param {Number=} offset
350 * @param {Number=} length
351 * @param {Number=} position
352 * @return {Promise}
353 */
354"write",
355/**
356 * Read data from the file specified by fd.
357 *
358 * @function module:fs.read
359 * @param {FileDescriptor} fd file descriptor
360 * @param {*} buffer
361 * @param {Number=} offset
362 * @param {Number=} length
363 * @param {Number=} position
364 * @return {Promise}
365 */
366"read",
367/**
368 * Reads the entire contents of a file.
369 *
370 * options:
371 * encoding String | Null default = null
372 * flag String default = 'r'
373 *
374 *
375 * If no encoding is specified, then the raw buffer is returned.
376 *
377 * @example
378 * fs.readFile('/etc/passwd').then(function(data) {
379 * console.log(data);
380 * });
381 *
382 * @function module:fs.readFile
383 * @param {String} filename
384 * @param {Object} options
385 * @return {Promise}
386 */
387"readFile",
388/**
389 * Writes data to a file, replacing the file if it already exists. data can be a string or a buffer.
390 *
391 * options:
392 * encoding String | Null default = 'utf8'
393 * mode Number default = 438 (aka 0666 in Octal)
394 * flag String default = 'w'
395 *
396 *
397 * If no encoding is specified, then the raw buffer is returned.
398 *
399 * @example
400 * fs.writeFile('message.txt', 'Hello Node').then(function() {
401 * console.log('Ok !');
402 * });
403 *
404 * @function module:fs.writeFile
405 * @param {String} filename
406 * @param {String|Buffer} data
407 * @param {Object=} options
408 * @return {Promise}
409 */
410"writeFile",
411/**
412 * Appends data to a file, creating the file if it not yet exists. data can be a string or a buffer.
413 *
414 * options:
415 * encoding String | Null default = 'utf8'
416 * mode Number default = 438 (aka 0666 in Octal)
417 * flag String default = 'a'
418 *
419 *
420 * If no encoding is specified, then the raw buffer is returned.
421 *
422 * @example
423 * fs.appendFile('message.txt', 'Hello Node').then(function() {
424 * console.log('Ok !');
425 * });
426 *
427 * @function module:fs.appendFile
428 * @param {String} filename
429 * @param {String|Buffer} data
430 * @param {Object=} options
431 * @return {Promise}
432 */
433"appendFile",
434/**
435 * Test whether or not the given path exists by checking with the file system.
436 * The promise result is either true or false.
437 *
438 * @example
439 * fs.exists('/etc/passwd', 'Hello Node').then(function(exists) {
440 * console.log(exists ? "it's there" : "no passwd!");
441 * });
442 *
443 * @function module:fs.exists
444 * @param {String} path
445 * @return {Promise}
446 */
447"exists"].forEach(function (name) {
44831 var fsFn = fs[name];
44931 exports[name] = function () {
45057 var args = arguments;
45157 return new Promise(function (resolve, reject) {
45257 Array.prototype.push.call(args, function (err) {
453 if (err) {
4541 return reject(err);
455 }
45656 var result = Array.prototype.slice.call(arguments, 1);
457 if (result.length === 1) {
45846 result = result[0];
459 }
46056 resolve(result);
461 });
46257 fsFn.apply(fs, args);
463 });
464 };
465});
466
467// Copy sync and other functions
4681Object.keys(fs).forEach(function (name) {
469 if (!exports[name]) {
47047 exports[name] = fs[name];
471 }
472});
473
474/**
475 * Read a file and parse its content as JSON
476 *
477 * @param {String} path
478 * @return {Promise}
479 */
4801var readJsonFile = function readJsonFile() {
4813 return exports.readFile.apply(exports, arguments).then(JSON.parse);
482};
483
4841exports.readJsonFile = readJsonFile;
485/**
486 * Read a file and parse its content as JSON synchronously
487 *
488 * @param {String} path
489 * @return {*}
490 */
4911var readJsonFileSync = function readJsonFileSync() {
4921 var result = fs.readFileSync.apply(fs, arguments);
4931 return result && JSON.parse(result);
494};
495
4961exports.readJsonFileSync = readJsonFileSync;
4971var writeJsonFile = function writeJsonFile() {
4981 var args = arguments;
4991 args[1] = JSON.stringify(args[1]);
5001 return exports.writeFile.apply(exports, args);
501};
502
5031exports.writeJsonFile = writeJsonFile;
5041var writePrettyJsonFile = function writePrettyJsonFile() {
5051 var args = arguments;
5061 args[1] = JSON.stringify(args[1], null, 4);
5071 return exports.writeFile.apply(exports, args);
508};
509
5101exports.writePrettyJsonFile = writePrettyJsonFile;
5111var parseYaml = function parseYaml(content) {
5123 return YAML.safeLoad(content.toString());
513};
514
5151var stringifyYaml = YAML.safeDump;
516
517/**
518 * Read a file and parse its content as Yaml
519 *
520 * @param {String} path
521 * @return {Promise}
522 */
5231var readYamlFile = function readYamlFile() {
5242 return exports.readFile.apply(exports, arguments).then(parseYaml);
525};
526
5271exports.readYamlFile = readYamlFile;
528/**
529 * Read a file and parse its content as Yaml synchronously
530 *
531 * @param {String} path
532 * @return {*}
533 */
5341var readYamlFileSync = function readYamlFileSync() {
5351 var result = fs.readFileSync.apply(fs, arguments);
5361 return result && parseYaml(result);
537};
538
5391exports.readYamlFileSync = readYamlFileSync;
540/**
541 * Write in file a yaml content
542 *
543 * @param {String} path
544 * @param {*} content
545 * @param {Object} options
546 * @return {*}
547 */
5481var writeYamlFile = function writeYamlFile() {
5491 var args = arguments;
5501 args[1] = stringifyYaml(args[1]);
5511 return exports.writeFile.apply(exports, args);
552};
553
5541exports.writeYamlFile = writeYamlFile;
555/**
556 * Recursively read a directory.
557 * callback is called for each files
558 * Return a Promise when all files are read.
559 *
560 * @param {String} dir
561 * @param {Object} options
562 * @param {Function} callback
563 * @return {Promise}
564 */
5651var readRecursiveDirectory = function readRecursiveDirectory(dir, options, callback) {
5664 options = Object.assign({
567 recursive: true,
568 directories: false }, options);
5694 return exports.readdir(dir).then(function (files) {
5704 return promisesUtils.forEach(files, function (file) {
57136 var path = dir + "/" + file;
57236 return exports.stat(path).then(function (stat) {
573 if (stat && stat.isDirectory()) {
574 if (options.directories) {
5751 return callback({ dirname: file, path: path, basedir: dir, stat: stat });
576 }
577 if (options.recursive) {
5781 return readRecursiveDirectory(path, options, callback);
579 }
580 } else {
58133 return callback({ filename: file, path: path, basedir: dir, stat: stat });
582 }
583 });
584 });
585 });
586};
5871exports.readRecursiveDirectory = readRecursiveDirectory;
588//# sourceMappingURL=fs.js.map

lib/generators.js

100%
12
12
0
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/**
7 * @module generators
8 */
9
10/**
11 * Generate a random code with the specified size
12 *
13 * @param {Number} size
14 * @param {String=} characters
15 * @return {Map}
16 */
171var randomCode = function randomCode(size, characters) {
181 characters = (characters || "abcdefghijklmnopqrstuvwxyz0123456789").split("").sort(function () {
19118 return 0.5 - Math.random();
20 }); // shuffle
21
221 var finalWord = "",
23 lastChar = "",
24 charBeforeLast = "";
251 var i = 0,
26 length = characters.length,
27 ch;
28 while (i++ < size) {
29 do {
3012 ch = characters[Math.floor(Math.random() * length)];
31 } while (ch === lastChar || ch === charBeforeLast);
3212 charBeforeLast = lastChar;
3312 finalWord += lastChar = ch;
34 }
351 return finalWord;
36};
371exports.randomCode = randomCode;
38//# sourceMappingURL=generators.js.map

lib/index.js

100%
76
76
0
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/**
7 * Utils
8 *
9 * @module utils
10 */
11
12/**
13 * shortcut for parseInt(value, 10)
14 *
15 * @param {String} value
16 * @return {Number} parsed int
17 */
181var toInt = function toInt(value) {
191 return parseInt(value, 10);
20};
21
221exports.toInt = toInt;
23/* IS */
24
25/**
26 * Test is a variable is a string
27 * @param {*} value
28 * @return {Boolean}
29 */
301var isString = function isString(value) {
3118 return typeof value === "string";
32};
33
341exports.isString = isString;
35/**
36 * Test is a variable is an object
37 * @param {*} value
38 * @return {Boolean}
39 */
401var isObject = function isObject(value) {
4117 return typeof value === "object";
42};
43
441exports.isObject = isObject;
45/**
46 * Test is a variable is a function
47 * @param {*} value
48 * @return {Boolean}
49 */
501var isFunction = function isFunction(value) {
512 return typeof value === "function";
52};
53
541exports.isFunction = isFunction;
55/**
56 * Test is a variable is a number
57 * @param {*} value
58 * @return {Boolean}
59 */
601var isNumber = function isNumber(value) {
612 return typeof value === "number";
62};
63
641exports.isNumber = isNumber;
65/**
66 * Test is a variable is a integer number
67 * @param {*} value
68 * @return {Boolean}
69 */
701var isInteger = function isInteger(value) {
712 return Number.isInteger(value);
72};
73
741exports.isInteger = isInteger;
75/**
76 * Test is a variable is an array
77 *
78 * @function
79 * @param {*} arg
80 * @return {Boolean}
81 */
821var isArray = Array.isArray;
83
841exports.isArray = isArray;
85/* HTML */
86
87/**
88 * Escape an html string
89 *
90 * @param {String} html string to be escaped
91 * @return {String} escaped string
92 */
931var escape = function escape(html) {
941 return String(html).replace(/&(?!\w+;)/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
95};
96
971exports.escape = escape;
98/**
99 * Escape an url for html
100 *
101 * @param {String} url
102 * @return {String} escaped url
103 */
1041var escapeUrl = function escapeUrl(html) {
1051 return html.replace(/&/g, "&");
106};
107
1081exports.escapeUrl = escapeUrl;
109/**
110 * Escape a string for regexp
111 *
112 * @param {String} string
113 * @return {String} escaped string
114 */
1151var regexpEscape = function regexpEscape(string) {
1164 return string.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1");
117};
118
1191exports.regexpEscape = regexpEscape;
120/**
121 * Shortcut for Object.defineProperty
122 *
123 * @param {Object} target
124 * @param {String} property name of the property
125 * @param {*} value value
126 * @param {Object=} options: writable default true, configurable default true, enumerable default false
127 * @return {Object} target
128 */
1291var defineProperty = function defineProperty(target, property, value, options) {
1301 Object.defineProperty(target, property, {
131 value: value,
132 writable: (options && options.writable) !== false,
133 configurable: (options && options.configurable) !== false,
134 enumerable: !!(options && options.enumerable)
135 });
1361 return target;
137};
138
1391exports.defineProperty = defineProperty;
140/**
141 * Shortcut for Object.defineProperty
142 *
143 * @param {Object} target
144 * @param {String} property name of the property
145 * @param {*} value value
146 * @param {Object=} options: enumerable default false
147 * @return {Object} target
148 */
1491var defineConstant = function defineConstant(target, property, value, options) {
1502 Object.defineProperty(target, property, {
151 value: value,
152 writable: false,
153 configurable: false,
154 enumerable: !!(options && options.enumerable)
155 });
1561 return target;
157};
158
1591exports.defineConstant = defineConstant;
160/**
161 * Shortcut for Object.defineProperty
162 *
163 * @param {Object} target
164 * @param {String} property name of the property
165 * @param {Function} getter getter function
166 * @param {Object=} options: configurable default true, enumerable default false
167 * @return {Object} target
168 */
1691var defineGetter = function defineGetter(target, property, getter, options) {
1701 Object.defineProperty(target, property, {
171 get: getter,
172 configurable: (options && options.configurable) !== false,
173 enumerable: !!(options && options.enumerable)
174 });
1751 return target;
176};
177
1781exports.defineGetter = defineGetter;
179/**
180 * Shortcut for Object.defineProperty
181 *
182 * @param {Object} target
183 * @param {String} property name of the property
184 * @param {Function} setter setter function
185 * @param {Object=} options: configurable default true, enumerable default false
186 * @return {Object} target
187 */
1881var defineSetter = function defineSetter(target, property, setter, options) {
1891 Object.defineProperty(target, property, {
190 set: setter,
191 configurable: (options && options.configurable) !== false,
192 enumerable: !!(options && options.enumerable)
193 });
1941 return target;
195};
196
1971exports.defineSetter = defineSetter;
198/**
199 * Shortcut for Object.defineProperties
200 *
201 * @param {Object} target
202 * @param {Object} properties
203 * @param {Object=} options: writable default true, configurable default true, enumerable default false
204 * @return {Object} target
205 */
2061var defineProperties = function defineProperties(target, properties, options) {
207 if (!properties) {
2081 return target;
209 }
2101 options = {
211 writable: (options && options.writable) !== false,
212 configurable: (options && options.configurable) !== false,
213 enumerable: !!(options && options.enumerable)
214 };
2151 Object.keys(properties).forEach(function (key) {
2162 Object.defineProperty(target, key, {
217 value: properties[key],
218 writable: options.writable,
219 configurable: options.configurable,
220 enumerable: options.enumerable
221 });
222 });
2231 return target;
224};
225
2261exports.defineProperties = defineProperties;
227/**
228 * The entries() method returns a new Iterator that contains the key/value pairs for each index in the Object|Array.
229 *
230 * @function module:utils.entries
231 * @param {Object|Array|Map} arg
232 * @param {Function} callback
233 * @param {*=} thisArg
234 * @return {Iterator}
235 */
236
237/**
238 * The filter() method creates a new Object|Array with all elements
239 * that pass the test implemented by the provided function.
240 *
241 * @function module:utils.filter
242 * @param {Object|Array} arg
243 * @param {Function} callback
244 * @param {*=} thisArg
245 * @return {Object|Array}
246 */
247
248/**
249 * The find() method returns a value in the Object|Array
250 * if an element in the Object|Array satisfies the provided testing function.
251 *
252 * @function module:utils.find
253 * @param {Object|Array} arg
254 * @param {Function} callback
255 * @param {*=} thisArg
256 * @return {*}
257 */
258
259/**
260 * The findIndex() method returns a value in the Object|Array
261 * if an element in the Object|Array satisfies the provided testing function.
262 *
263 * @function module:utils.findIndex
264 * @param {Object|Array} arg
265 * @param {Function} callback
266 * @param {*=} thisArg
267 * @return {number|string|undefined}
268 */
269
270/**
271 * The forEach() method executes a provided function once per Object|Array element.
272 *
273 * @function module:utils.forEach
274 * @param {Object|Array|Map} arg
275 * @param {Function} callback
276 * @param {*=} thisArg
277 * @return {number|string|undefined}
278 */
279
280/**
281 * The join() method joins all elements of an Object|Array into a string.
282 *
283 * @function module:utils.join
284 * @param {Object|Array} arg
285 * @param {String} separator
286 * @return {String}
287 */
288
289/**
290 * The map() method creates a new Object|Array with the results
291 * of calling a provided function on every element in this Object|Array.
292 *
293 * @function module:utils.map
294 * @param {Object|Array} arg
295 * @param {Function} callback
296 * @param {*=} thisArg
297 * @return {Object|Array}
298 */
299
300/**
301 * The reduce() method applies a function against an accumulator
302 * and each value of the Object|Array (from left-to-right) has to reduce it to a single value.
303 *
304 * @function module:utils.reduce
305 * @param {Object|Array} arg
306 * @param {Function} callback callback(previousValue, currentKey, currentValue, objectOrArray)
307 * @param {*=} initialValue
308 * @return {*}
309 */
310
311// TODO http://usejsdoc.org/tags-callback.html
312/**
313 * The reduceRight() method applies a function against an accumulator
314 * and each value of the Object|Array (from right-to-left) has to reduce it to a single value.
315 *
316 * @function module:utils.reduceRight
317 * @param {Object|Array} arg
318 * @param {Function} callback callback(previousValue, currentKey, currentValue, objectOrArray)
319 * @param {*=} initialValue
320 * @return {*}
321 */
322
323/**
324 * The some() method tests whether some element in the Object|Array
325 * passes the test implemented by the provided function.
326 *
327 * @function module:utils.some
328 * @param {Object|Array} arg
329 * @param {Function} callback
330 * @param {*=} thisArg
331 * @return {*}
332 */
333
3341"entries filter find findIndex forEach join map reduce reduceRight some".split(" ").forEach(function (methodName) {
33510 exports[methodName] = function (arrayOrObject) {
33633 var args = Array.prototype.slice.call(arguments, 1);
33733 var method = arrayOrObject[methodName];
338 if (!method) {
33916 method = exports.object[methodName];
34016 args.unshift(arrayOrObject);
341 }
34233 return method.apply(arrayOrObject, args);
343 };
344});
345
346/**
347 * The mapToArray() method creates a new array with the results
348 * of calling a provided function on every element in this Object|Array.
349 *
350 * @function module:utils.mapToArray
351 * @param {Object|Array|Map} arg
352 * @param {Function} callback
353 * @param {*=} thisArg
354 * @return {Array}
355 */
356
3571var mapToArray = function mapToArray(arrayOrObject, callback) {
358 if (Array.isArray(arrayOrObject)) {
3591 return arrayOrObject.map(callback);
360 }
3612 var array = [];
3622 exports.forEach(arrayOrObject, function (value, index) {
3634 array.push(callback(value, index));
364 });
3652 return array;
366};
367
3681exports.mapToArray = mapToArray;
369/**
370 * Access to the array module
371 *
372 * @constant module:utils.array
373 * @type module:array
374 */
3751var array = require("./array");
376
3771exports.array = array;
378/**
379 * Access to the object module
380 *
381 * @constant module:utils.object
382 * @type module:object
383 */
3841var object = require("./object");
385
3861exports.object = object;
387/**
388 * Access to the string module
389 *
390 * @constant module:utils.string
391 * @type module:string
392 */
3931var string = require("./string/string");
394
3951exports.string = string;
396/**
397 * Access to the promises module
398 *
399 * @constant module:utils.promises
400 * @type module:promises
401 */
4021var promises = require("./promises");
4031exports.promises = promises;
404//# sourceMappingURL=index.js.map

lib/object.js

98%
71
70
1
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/**
7 * @module object
8 */
9
10/**
11 * Transforms an object into a Map
12 *
13 * @param {Object|Map} object
14 * @return {Map}
15 */
161var toMap = function toMap(object) {
17 if (object instanceof Map) {
181 return object;
19 }
201 var map = new Map();
21 for (var key in object) {
222 map.set(key, object[key]);
23 }
241 return map;
25};
26
271exports.toMap = toMap;
28/**
29 * Same as Object.assign, but doesn't override the value if !== undefined
30 *
31 * @param {Object} target
32 * @param {Object} object
33 * @return {Object} target
34 */
351var union = function union(target) {
361 Array.from(arguments).slice(1).forEach(function (object) {
37 if (object) {
38 for (var key in object) {
39 if (target[key] === undefined) {
402 target[key] = object[key];
41 }
42 }
43 }
44 });
451 return target;
46};
47
481exports.union = union;
49/**
50 * Clones an object
51 *
52 * @param {Object} object
53 * @return {Object} target
54 */
551var clone = function clone(object) {
561 return Object.assign({}, object);
57};
58
591exports.clone = clone;
60/**
61 * Filter an object by the keys
62 *
63 * @param {Object} object
64 * @param {Array} keys
65 * @return {Object}
66 */
671var filterKeys = function filterKeys(object, keys) {
682 var filteredObject = {};
692 keys.forEach(function (k) {
704 filteredObject[k] = object[k];
71 });
722 return filteredObject;
73};
74
751exports.filterKeys = filterKeys;
76/**
77 * Same a map + join
78 *
79 * @param {Object} object
80 * @param {Array} keys
81 * @return {Object}
82 */
831var mapJoin = function mapJoin(object, separator, callback) {
84 if (typeof separator === "function") {
851 callback = separator;
861 separator = "";
87 }
882 object = exports.map(object, callback);
892 return exports.join(object, separator);
90};
91
921exports.mapJoin = mapJoin;
93// Array-like functions
941var _commonObjectArray = function _commonObjectArray(propertyName, object, callback, thisArg) {
95 if (!thisArg) {
9611 thisArg = object;
97 }
98 /*#if DEV*/
99 if (object[propertyName]) {
1000 throw new Error("call " + propertyName + " !");
101 }
102 /*#/if*/
10312 return Object.keys(object)[propertyName](function (key) {
10431 return callback.call(thisArg, object[key], key);
105 });
106};
107
108/**
109 * The entries() method returns a new Iterator that contains the key/value pairs for each index in the Object.
110*
111* @param {Object|Map} object
112* @return {Iterator}
113*/
1141var entries = function entries(object) {
1151 var keys = Object.keys(object),
116 i = 0;
1171 return Object.freeze({
118 next: function next() {
119 if (i >= keys.length) {
1201 return Object.freeze({ done: true });
121 }
1222 return Object.freeze({ value: [keys[i], object[keys[i++]]], done: false });
123 }
124 });
125};
126
1271exports.entries = entries;
128/**
129* The filter() method creates a new object with all elements that pass the test implemented by the provided function.
130*
131* @param {Object} object
132* @param {Function} callback
133* @param {*=} thisArg
134* @return {Object}
135*/
1361var filter = function filter(object, callback, thisArg) {
1371 var keys = _commonObjectArray.call(null, "filter", object, callback, thisArg);
1381 return exports.filterKeys(object, keys);
139};
140
1411exports.filter = filter;
142/**
143* The find() method returns a value in the object,
144* if an element in the object satisfies the provided testing function. Otherwise undefined is returned.
145*
146* @param {Object} object
147* @param {Function} callback
148* @param {*=} thisArg
149* @return {*}
150*/
1511var find = function find(object, callback, thisArg) {
1521 var key = exports.findIndex.apply(null, arguments);
1531 return key && object[key];
154};
155
1561exports.find = find;
157/**
158* The findIndex() method returns an key in the object,
159* if an element in the object satisfies the provided testing function. Otherwise undefined is returned.
160*
161* @function
162* @param {Object} object
163* @param {Function} callback
164* @param {*=} thisArg
165* @return {String|undefined}
166*/
1671var findIndex = _commonObjectArray.bind(null, "find");
168
1691exports.findIndex = findIndex;
170/**
171* The forEach() method executes a provided function once per object element.
172*
173* @function
174* @param {Object|Map} object
175* @param {Function} callback
176* @param {*} thisArg
177* @return {*}
178*/
1791var forEach = _commonObjectArray.bind(null, "forEach");
180
1811exports.forEach = forEach;
182/**
183* The join() method joins all elements of an object into a string.
184*
185* @param {Object} object
186* @param {String} separator
187* @return {String}
188*/
1891var join = function join(object, separator) {
1903 return Object.keys(object).map(function (key) {
1917 return object[key];
192 }).join(separator);
193};
194
1951exports.join = join;
196/**
197* The map() method creates a new object with the results of calling a provided function on every element in this object.
198*
199* @param {Object} object
200* @param {Function} callback
201* @param {*=} thisArg
202* @return {*}
203*/
2041var map = function map(object, callback, thisArg) {
2055 var mappedObject = {};
2065 exports.forEach(object, function (value, key) {
20713 mappedObject[key] = callback.apply(this, arguments);
208 });
2095 return mappedObject;
210};
211
2121exports.map = map;
213/**
214* The reduce() method applies a function against an accumulator
215* and each value of the object (from left-to-right) has to reduce it to a single value.
216*
217* @param {Object} object
218* @param {Function} callback
219* @param {*=} initialValue
220* @return {*}
221*/
2221var reduce = function reduce(object, callback, initialValue) {
2232 return Object.keys(object).reduce(function (previousValue, currentValue, index, array) {
2246 return callback(previousValue, object[currentValue], currentValue, object);
225 }, initialValue);
226};
227
2281exports.reduce = reduce;
229/**
230* The reduceRight() method applies a function against an accumulator
231* and each value of the object (from right-to-left) as to reduce it to a single value.
232*
233* @param {Object} object
234* @param {Function} callback
235* @param {*=} initialValue
236* @return {*}
237*/
2381var reduceRight = function reduceRight(object, callback, initialValue) {
2392 return Object.keys(object).reduceRight(function (previousValue, currentValue, index, array) {
2406 return callback(previousValue, object[currentValue], currentValue, object);
241 }, initialValue);
242};
243
2441exports.reduceRight = reduceRight;
245/**
246* The some() method tests whether some element in the object passes the test implemented by the provided function.
247*
248* @function
249* @param {Object} object
250* @param {Function} callback
251* @param {*=} thisArg
252* @return {Boolean}
253*/
2541var some = _commonObjectArray.bind(null, "some");
2551exports.some = some;
256//# sourceMappingURL=object.js.map

lib/php.js

94%
37
35
2
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/* jshint freeze: false */
7
81var S = require("./index");
9
10if (!String.prototype.contains) {
111 String.prototype.contains = function () {
1261 return String.prototype.indexOf.apply(this, arguments) !== -1;
13 };
14}
15
16/**
17 * Php utils
18 *
19 * @module php
20 */
21
22/**
23 * Export string into a php string in string
24 *
25 * @param {String} str
26 * @return {String}
27 */
281var exportString = function exportString(str) {
29 if (str.contains("\n") || str.contains("\r") || str.contains("\t") || str.contains("\u000b") || str.contains("\f")) {
302 return "\"" + str.replace(/\\/g, "\\\\").replace(/\n/g, "\n").replace(/\r/g, "\r").replace(/\t/g, "\t").replace(/\v/g, "\u000b").replace(/\f/g, "\f").replace(/\$/, "$") + "\"";
31 }
32 if (!str.contains("'")) {
336 return "'" + str + "'";
34 }
35 if (!str.contains("\"")) {
362 return "\"" + str.replace(/\$/g, "$") + "\"";
37 }
381 return "'" + str.replace(/\'/g, "\\'") + "'";
39};
40
411exports.exportString = exportString;
421var _exportCodeVar = function _exportCodeVar(v) {
43 if (S.isString(v)) {
448 return exportString(v);
45 }
46 if (v === undefined || v === null) {
471 return "null";
48 }
49 if (v === true) {
501 return "true";
51 }
52 if (v === false) {
531 return "false";
54 }
555 return v; // numeric
56};
57
581exports._exportCodeVar = _exportCodeVar;
591var _exportCode = (function (_exportCode2) {
601 var _exportCodeWrapper = function _exportCode(_x, _x2) {
6116 return _exportCode2.apply(this, arguments);
62 };
63
641 _exportCodeWrapper.toString = function () {
650 return _exportCode2.toString();
66 };
67
681 return _exportCodeWrapper;
69})(function (v, start) {
70 if (v === null || !S.isObject(v)) {
7113 return _exportCodeVar(v);
72 }
73
743 var content = "array(";
75 if (S.isArray(v)) {
76 for (var i = 0, l = v.length; i < l; i++) {
775 content += _exportCode(v[i]) + ",";
78 }
79 } else {
80 for (var k in v) {
813 content += _exportCodeVar(k) + "=>" + _exportCode(v[k]) + ",";
82 }
83 }
84 if (content) {
853 content = content.replace(/,+$/, "");
86 }
873 content += start ? ")" : "),";
883 return content;
89});
90
911exports._exportCode = _exportCode;
92/**
93 * Export javascript object into a php code in string
94 *
95 * @param {any} v
96 * @param {bool} ifEmptyArray
97 * @return {String}
98 */
991var exportCode = function exportCode(v, ifEmptyArray) {
1008 var content = _exportCode(v, true);
101 if (ifEmptyArray !== undefined && (content === "false" || content === "array()")) {
1020 return ifEmptyArray;
103 }
1048 return content;
105};
1061exports.exportCode = exportCode;
107//# sourceMappingURL=php.js.map

lib/promises.js

100%
74
74
0
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
61var S = require("./index");
7
81var createdPromise;
9
10/**
11 * @module promises
12 */
13
14/**
15 * Creates a callback that resolve or reject a promise
16 * according to the default callback convention in node: (err, result)
17 *
18 * @param {Function} resolve resolve function of the promise
19 * @param {Function} reject reject function of the promise
20 * @return {Function}
21 */
221var resolveFromCallback = function resolveFromCallback(resolve, reject) {
234 return function (err, result) {
24 if (err) {
251 return reject(err);
26 }
273 resolve(result);
28 };
29};
30
311exports.resolveFromCallback = resolveFromCallback;
32/**
33 * Returns a promise
34 *
35 * The first argument is a callback with a done function
36 *
37 * @example
38 * S.promiseCallback((done) => {
39 * fs.readFile('./myFile.txt', done);
40 * }).then((txtContentBuffer) => {
41 * console.log(txtContentBuffer.toString());
42 * });
43 *
44 * @param {Function} callback callback((done) => {})
45 * @return {Promise}
46 */
471var promiseCallback = function promiseCallback(callback) {
481 var resolveCallback, rejectCallback;
491 var createdPromise = new Promise(function (resolve, reject) {
501 resolveCallback = resolve;
511 rejectCallback = reject;
52 });
531 var doneCallback = resolveFromCallback(resolveCallback, rejectCallback);
541 callback(doneCallback);
551 return createdPromise;
56};
57
581exports.promiseCallback = promiseCallback;
59/**
60 * Returns an array with two values : the promise and the callback to call
61 *
62 * @deprecated Prefer use of S.promiseCallback()
63 *
64 * @example
65 * var [promise, doneCallback] = promises.creator();
66 * fs.readFile('./myFile.txt', doneCallback);
67 * promise.then((txtContentBuffer) => {
68 * console.log(txtContentBuffer.toString());
69 * });
70 *
71 * @return {Array}
72 */
731var creator = function creator() {
741 var resolveCallback, rejectCallback;
751 var createdPromise = new Promise(function (resolve, reject) {
761 resolveCallback = resolve;
771 rejectCallback = reject;
78 });
791 var doneCallback = resolveFromCallback(resolveCallback, rejectCallback);
801 return [createdPromise, doneCallback];
81};
82
831exports.creator = creator;
84/**
85 * Returns a callback that resolve or reject the created promise that you can get with {promises}
86 *
87 * @deprecated Prefer use of S.promiseCallback()
88 *
89 * @return {Function} callback(err, result)
90 */
911var done = function done() {
922 var resolveCallback, rejectCallback;
932 createdPromise = new Promise(function (resolve, reject) {
942 resolveCallback = resolve;
952 rejectCallback = reject;
96 });
972 return resolveFromCallback(resolveCallback, rejectCallback);
98};
99
1001exports.done = done;
101/**
102* Returns the Promise created by the previously called method done()
103*
104* @deprecated Prefer use of S.promiseCallback()
105*
106* @example
107* promises.promise(callback(promises.done()));
108*
109* @return {Promise}
110*/
1111var promise = function promise() {
112 if (!createdPromise) {
1131 throw new Error("No promise in stack, done() should be called before");
114 }
1152 var p = createdPromise;
1162 createdPromise = undefined;
1172 return p;
118};
119
1201exports.promise = promise;
121/**
122 * Execute promises in parallel
123 *
124 * @param {Array|Object|Map|Set} iterable an iterable with .map method (like Array), or an key/value object
125 * @param {Function} callback callback(value, index) called for each values
126 * @return {Promise}
127 */
1281var forEach = function forEach(iterable, callback) {
129 if (Array.isArray(iterable)) {
1308 return Promise.all(iterable.map(callback));
131 }
1321 var keys = [],
133 values = [];
1341 S.forEach(S.map(iterable, callback), function (value, index) {
1353 keys.push(index);
1363 values.push(value);
137 });
138
1391 return Promise.all(values).then(function (results) {
1401 return S.map(iterable, function (value, index) {
1413 return results[keys.indexOf(index)];
142 });
143 });
144};
145
1461exports.forEach = forEach;
147/**
148 * Execute promises in series
149 *
150 * @param {Array|Object} iterable an iterable with .map method (like Array), or an key/value object
151 * @param {Function} callback callback(value, index) called for each values
152 * @return {Promise}
153 */
1541var forEachSeries = function forEachSeries(iterable, callback) {
1552 return new Promise(function (resolve, reject) {
1562 var entriesIterator = S.entries(iterable);
1572 var results = new iterable.constructor();
1582 (function next() {
1596 var current = entriesIterator.next();
160 if (current.done) {
1612 return resolve(results);
162 }
1634 var key = current.value[0],
164 value = current.value[1];
1654 var result = callback(value, key);
166 if (result && typeof result.then === "function") {
1673 result.then(function (result) {
1683 results[key] = result;
1693 next();
170 })["catch"](reject);
171 } else {
1721 results[key] = result;
1731 setImmediate(next);
174 }
175 })();
176 });
177};
178
1791exports.forEachSeries = forEachSeries;
180/**
181 * Execute the second callback wile the first callback is true
182 *
183 * @param {Function} iterable an iterable with .map method (like Array), or an key/value object
184 * @param {Function} callback callback(value, index) called for each values
185 * @return {Promise}
186 */
1871var whileTrue = function whileTrue(conditionCallback, callback) {
1881 return new Promise(function (resolve, reject) {
1891 (function next() {
190 if (!conditionCallback()) {
1911 return resolve();
192 }
1933 var result = callback();
194 if (result && typeof result.then === "function") {
1951 result.then(function () {
1961 setImmediate(next);
197 })["catch"](reject);
198 } else {
1992 setImmediate(next);
200 }
201 })();
202 });
203};
204
2051exports.whileTrue = whileTrue;
206/**
207 * Returns a promise
208 *
209 * The first argument is a callback with a done function
210 *
211 * @example
212 * S.promiseCallback((done) => {
213 * fs.readFile('./myFile.txt', done);
214 * }).then((txtContentBuffer) => {
215 * console.log(txtContentBuffer.toString());
216 * });
217 *
218 * @function module:utils.promiseCallback
219 * @param {Function} callback callback((done) => {})
220 * @return {Promise}
221 */
2221S.promiseCallback = promiseCallback;
223//# sourceMappingURL=promises.js.map

lib/security.js

100%
18
18
0
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
61var crypto = require("crypto");
7
8/**
9 * Security
10 * Only for NodeJS
11 *
12 * @module security
13 */
14
15/**
16 * Create an md5 hash
17 *
18 * @param {Buffer|String} data
19 * @return {String} base64 string
20 */
211var md5 = function md5(data) {
221 var shasum = crypto.createHash("md5");
231 shasum.update(data);
241 return shasum.digest("base64");
25};
26
271exports.md5 = md5;
28/**
29 * Create an sha1 hash
30 *
31 * @param {Buffer|String} data
32 * @return {String} base64 string
33 */
341var sha1 = function sha1(data) {
351 var shasum = crypto.createHash("sha1");
361 shasum.update(data);
371 return shasum.digest("base64");
38};
39
401exports.sha1 = sha1;
41/**
42 * Create an sha512 hash
43 *
44 * @param {Buffer|String} data
45 * @return {String} base64 string
46 */
471var sha512 = function sha512(data) {
481 var shasum = crypto.createHash("sha512");
491 shasum.update(data);
501 return shasum.digest("base64");
51};
521exports.sha512 = sha512;
53//# sourceMappingURL=security.js.map

lib/string/html.js

100%
19
19
0
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/**
7 * @module string
8 */
91var exports = require("./string");
101module.exports = exports;
11
12/* http://phpjs.org/functions/strip_tags:535 */
13/**
14 * Strip html tags from a string, trying to keep newlines consistent
15 * @param {String} s
16 * @param {String} allowed list of allowed tags, separated by space
17 * @return {String}
18 */
191var stripTags = function stripTags(s, allowed) {
206 allowed = (allowed || "").toLowerCase().split(" ");
216 var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;
226 var commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
23 /* http://www.tutorialchip.com/tutorials/html5-block-level-elements-complete-list/ */
246 var blockTags = ("article aside blockquote br dd div dl dt embed fieldset figcaption figure footer form" + " h1 h2 h3 h4 h5 h6 header hgroup hr li menu nav ol output p pre" + " section table tbody textarea tfoot th thead tr ul").split(" ");
256 return s.replace(commentsAndPhpTags, "").replace(tags, function ($0, tag) {
2616 tag = tag.toLowerCase();
2716 return allowed.indexOf(tag) !== -1 ? $0 : blockTags.indexOf(tag) !== -1 ? "\n" : "";
28 }).replace(/\s*\n+\s*\n*/g, "\n").trim();
29};
30
311exports.stripTags = stripTags;
32/**
33 * Transform new lines (\r?\n) to br
34 *
35 * @param {String} string
36 * @return {String}
37 */
381var nl2br = function nl2br(string) {
391 return string.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, "$1<br>$2");
40};
41
421exports.nl2br = nl2br;
43/**
44 * Transform <br> to new lines
45 *
46 * @param {String} string
47 * @return {String}
48 */
491var br2nl = function br2nl(string) {
501 return string.replace(/<br\s*\/?>/g, "\n");
51};
521exports.br2nl = br2nl;
53//# sourceMappingURL=../string/html.js.map

lib/string/normalize.js

100%
16
16
0
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/**
7 * @module string
8 */
91var utils = require("../index");
101var exports = require("./string");
111module.exports = exports;
12
13/**
14 * Transliterate a string
15 *
16 * @param {String} string
17 * @return {String}
18 */
191var translit = function translit(string) {
204 return [[/æ|ǽ/g, "ae"], [/œ/g, "oe"], [/Œ/g, "OE"], [/Ä|À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ/g, "A"], [/ä|à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª/g, "a"], [/Ç|Ć|Ĉ|Ċ|Č/g, "C"], [/ç|ć|ĉ|ċ|č/g, "c"], [/Ð|Ď|Đ/g, "D"], [/ð|ď|đ/g, "d"], [/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|€/g, "E"], [/è|é|ê|ë|ē|ĕ|ė|ę|ě/g, "e"], [/Ĝ|Ğ|Ġ|Ģ/g, "G"], [/ĝ|ğ|ġ|ģ/g, "g"], [/Ĥ|Ħ/g, "H"], [/ĥ|ħ/g, "h"], [/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ/g, "I"], [/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı/g, "i"], [/Ĵ/g, "J"], [/ĵ/g, "j"], [/Ķ/g, "K"], [/ķ/g, "k"], [/Ĺ|Ļ|Ľ|Ŀ|Ł/g, "L"], [/ĺ|ļ|ľ|ŀ|ł/g, "l"], [/Ñ|Ń|Ņ|Ň/g, "N"], [/ñ|ń|ņ|ň|ʼn/g, "n"], [/Ö|Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ/g, "O"], [/ö|ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|°/g, "o"], [/Ŕ|Ŗ|Ř/g, "R"], [/ŕ|ŗ|ř/g, "r"], [/Ś|Ŝ|Ş|Š/g, "S"], [/ś|ŝ|ş|š|ſ/g, "s"], [/Ţ|Ť|Ŧ/g, "T"], [/ţ|ť|ŧ/g, "t"], [/Ü|Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ/g, "U"], [/ü|ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ/g, "u"], [/Ý|Ÿ|Ŷ/g, "Y"], [/ý|ÿ|ŷ/g, "y"], [/Ŵ/g, "W"], [/ŵ/g, "w"], [/Ź|Ż|Ž/g, "Z"], [/ź|ż|ž/g, "z"], [/Æ|Ǽ/g, "AE"], [/ß/g, "ss"], [/IJ/g, "IJ"], [/ij/g, "ij"], [/ƒ/g, "f"], [/&/g, "et"], [/þ/g, "th"], [/Þ/g, "TH"]].reduce(function (string, v) {
21196 return string.replace(v[0], v[1]);
22 }, string);
23};
24
251exports.translit = translit;
26/**
27 * Normalize a string
28 *
29 * @param {String} string
30 * @return {String}
31 */
321var normalize = function normalize(string) {
331 return translit(string).replace(/[ \-\'\"\_\(\)\[\]\{\}\#\~\&\*\,\.\;\:\!\?\/\\\\|\`<\>\+]+/g, " ").trim().toLowerCase();
34};
35
361exports.normalize = normalize;
37/**
38 * Slugify a string
39 *
40 * @param {String} string
41 * @return {String}
42 */
431var slugify = function slugify(string) {
442 var replacement = arguments[1] === undefined ? "-" : arguments[1];
45
462 return translit(string.trim()).replace(/([^\d\.])\.+([^\d\.]|$)/g, "$1 $2").replace(/[^a-zA-Z\d\.]/g, " ") // \w is a-z and _
47 .trim().replace(/\s+/g, replacement).replace(new RegExp("^" + utils.regexpEscape(replacement) + "+|" + utils.regexpEscape(replacement) + "+$"), "");
48};
491exports.slugify = slugify;
50//# sourceMappingURL=../string/normalize.js.map

lib/string/string.js

100%
19
19
0
LineHitsSource
11"use strict";
2
31Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/**
7 * @module string
8 */
9
10/**
11 * Make a string's first character lowercase
12 *
13 * @param {String} string
14 * @return {String}
15 */
161var lcFirst = function lcFirst(string) {
175 return string.charAt(0).toLowerCase() + string.substr(1);
18};
19
201exports.lcFirst = lcFirst;
21/**
22 * Make a string's first character uppercase
23 *
24 * @param {String} string
25 * @return {String}
26 */
271var ucFirst = function ucFirst(string) {
285 return string.charAt(0).toUpperCase() + string.substr(1);
29};
30
311exports.ucFirst = ucFirst;
32/**
33 * Test if a string is empty
34 *
35 * @param {String} string
36 * @return {Boolean}
37 */
381var isEmpty = function isEmpty(string) {
394 return string.trim() === "";
40};
41
421exports.isEmpty = isEmpty;
43/**
44 * Format a string using %s
45 *
46 * @param {String} string
47 * @param {...String} args
48 * @return {String}
49 */
501var format = function format(string) {
512 return exports.vformat(string, Array.prototype.slice.call(arguments, 1));
52};
53
541exports.format = format;
55/**
56 * Format a string using %s
57 *
58 * @param {String} string
59 * @param {string[]} args
60 * @return {String}
61 */
621var vformat = function vformat(string, args) {
634 var i = 0;
644 return string.replace(/%s/g, function (m) {
658 return args[i++] || "";
66 });
67};
681exports.vformat = vformat;
69//# sourceMappingURL=../string/string.js.map