]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npmlog/node_modules/gauge/node_modules/lodash.pad/index.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / npmlog / node_modules / gauge / node_modules / lodash.pad / index.js
1 /**
2  * lodash (Custom Build) <https://lodash.com/>
3  * Build: `lodash modularize exports="npm" -o ./`
4  * Copyright jQuery Foundation and other contributors <https://jquery.org/>
5  * Released under MIT license <https://lodash.com/license>
6  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7  * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8  */
9 var baseSlice = require('lodash._baseslice'),
10     baseToString = require('lodash._basetostring'),
11     toString = require('lodash.tostring');
12
13 /** Used as references for various `Number` constants. */
14 var INFINITY = 1 / 0,
15     MAX_SAFE_INTEGER = 9007199254740991,
16     MAX_INTEGER = 1.7976931348623157e+308,
17     NAN = 0 / 0;
18
19 /** `Object#toString` result references. */
20 var funcTag = '[object Function]',
21     genTag = '[object GeneratorFunction]',
22     symbolTag = '[object Symbol]';
23
24 /** Used to match leading and trailing whitespace. */
25 var reTrim = /^\s+|\s+$/g;
26
27 /** Used to detect bad signed hexadecimal string values. */
28 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
29
30 /** Used to detect binary string values. */
31 var reIsBinary = /^0b[01]+$/i;
32
33 /** Used to detect octal string values. */
34 var reIsOctal = /^0o[0-7]+$/i;
35
36 /** Used to compose unicode character classes. */
37 var rsAstralRange = '\\ud800-\\udfff',
38     rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
39     rsComboSymbolsRange = '\\u20d0-\\u20f0',
40     rsVarRange = '\\ufe0e\\ufe0f';
41
42 /** Used to compose unicode capture groups. */
43 var rsAstral = '[' + rsAstralRange + ']',
44     rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
45     rsFitz = '\\ud83c[\\udffb-\\udfff]',
46     rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
47     rsNonAstral = '[^' + rsAstralRange + ']',
48     rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
49     rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
50     rsZWJ = '\\u200d';
51
52 /** Used to compose unicode regexes. */
53 var reOptMod = rsModifier + '?',
54     rsOptVar = '[' + rsVarRange + ']?',
55     rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
56     rsSeq = rsOptVar + reOptMod + rsOptJoin,
57     rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
58
59 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
60 var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
61
62 /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
63 var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange  + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
64
65 /** Built-in method references without a dependency on `root`. */
66 var freeParseInt = parseInt;
67
68 /**
69  * Gets the number of symbols in `string`.
70  *
71  * @private
72  * @param {string} string The string to inspect.
73  * @returns {number} Returns the string size.
74  */
75 function stringSize(string) {
76   if (!(string && reHasComplexSymbol.test(string))) {
77     return string.length;
78   }
79   var result = reComplexSymbol.lastIndex = 0;
80   while (reComplexSymbol.test(string)) {
81     result++;
82   }
83   return result;
84 }
85
86 /**
87  * Converts `string` to an array.
88  *
89  * @private
90  * @param {string} string The string to convert.
91  * @returns {Array} Returns the converted array.
92  */
93 function stringToArray(string) {
94   return string.match(reComplexSymbol);
95 }
96
97 /** Used for built-in method references. */
98 var objectProto = Object.prototype;
99
100 /**
101  * Used to resolve the
102  * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
103  * of values.
104  */
105 var objectToString = objectProto.toString;
106
107 /* Built-in method references for those with the same name as other `lodash` methods. */
108 var nativeCeil = Math.ceil,
109     nativeFloor = Math.floor;
110
111 /**
112  * The base implementation of `_.repeat` which doesn't coerce arguments.
113  *
114  * @private
115  * @param {string} string The string to repeat.
116  * @param {number} n The number of times to repeat the string.
117  * @returns {string} Returns the repeated string.
118  */
119 function baseRepeat(string, n) {
120   var result = '';
121   if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
122     return result;
123   }
124   // Leverage the exponentiation by squaring algorithm for a faster repeat.
125   // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
126   do {
127     if (n % 2) {
128       result += string;
129     }
130     n = nativeFloor(n / 2);
131     if (n) {
132       string += string;
133     }
134   } while (n);
135
136   return result;
137 }
138
139 /**
140  * Casts `array` to a slice if it's needed.
141  *
142  * @private
143  * @param {Array} array The array to inspect.
144  * @param {number} start The start position.
145  * @param {number} [end=array.length] The end position.
146  * @returns {Array} Returns the cast slice.
147  */
148 function castSlice(array, start, end) {
149   var length = array.length;
150   end = end === undefined ? length : end;
151   return (!start && end >= length) ? array : baseSlice(array, start, end);
152 }
153
154 /**
155  * Creates the padding for `string` based on `length`. The `chars` string
156  * is truncated if the number of characters exceeds `length`.
157  *
158  * @private
159  * @param {number} length The padding length.
160  * @param {string} [chars=' '] The string used as padding.
161  * @returns {string} Returns the padding for `string`.
162  */
163 function createPadding(length, chars) {
164   chars = chars === undefined ? ' ' : baseToString(chars);
165
166   var charsLength = chars.length;
167   if (charsLength < 2) {
168     return charsLength ? baseRepeat(chars, length) : chars;
169   }
170   var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
171   return reHasComplexSymbol.test(chars)
172     ? castSlice(stringToArray(result), 0, length).join('')
173     : result.slice(0, length);
174 }
175
176 /**
177  * Checks if `value` is classified as a `Function` object.
178  *
179  * @static
180  * @memberOf _
181  * @since 0.1.0
182  * @category Lang
183  * @param {*} value The value to check.
184  * @returns {boolean} Returns `true` if `value` is correctly classified,
185  *  else `false`.
186  * @example
187  *
188  * _.isFunction(_);
189  * // => true
190  *
191  * _.isFunction(/abc/);
192  * // => false
193  */
194 function isFunction(value) {
195   // The use of `Object#toString` avoids issues with the `typeof` operator
196   // in Safari 8 which returns 'object' for typed array and weak map constructors,
197   // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
198   var tag = isObject(value) ? objectToString.call(value) : '';
199   return tag == funcTag || tag == genTag;
200 }
201
202 /**
203  * Checks if `value` is the
204  * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
205  * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
206  *
207  * @static
208  * @memberOf _
209  * @since 0.1.0
210  * @category Lang
211  * @param {*} value The value to check.
212  * @returns {boolean} Returns `true` if `value` is an object, else `false`.
213  * @example
214  *
215  * _.isObject({});
216  * // => true
217  *
218  * _.isObject([1, 2, 3]);
219  * // => true
220  *
221  * _.isObject(_.noop);
222  * // => true
223  *
224  * _.isObject(null);
225  * // => false
226  */
227 function isObject(value) {
228   var type = typeof value;
229   return !!value && (type == 'object' || type == 'function');
230 }
231
232 /**
233  * Checks if `value` is object-like. A value is object-like if it's not `null`
234  * and has a `typeof` result of "object".
235  *
236  * @static
237  * @memberOf _
238  * @since 4.0.0
239  * @category Lang
240  * @param {*} value The value to check.
241  * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
242  * @example
243  *
244  * _.isObjectLike({});
245  * // => true
246  *
247  * _.isObjectLike([1, 2, 3]);
248  * // => true
249  *
250  * _.isObjectLike(_.noop);
251  * // => false
252  *
253  * _.isObjectLike(null);
254  * // => false
255  */
256 function isObjectLike(value) {
257   return !!value && typeof value == 'object';
258 }
259
260 /**
261  * Checks if `value` is classified as a `Symbol` primitive or object.
262  *
263  * @static
264  * @memberOf _
265  * @since 4.0.0
266  * @category Lang
267  * @param {*} value The value to check.
268  * @returns {boolean} Returns `true` if `value` is correctly classified,
269  *  else `false`.
270  * @example
271  *
272  * _.isSymbol(Symbol.iterator);
273  * // => true
274  *
275  * _.isSymbol('abc');
276  * // => false
277  */
278 function isSymbol(value) {
279   return typeof value == 'symbol' ||
280     (isObjectLike(value) && objectToString.call(value) == symbolTag);
281 }
282
283 /**
284  * Converts `value` to a finite number.
285  *
286  * @static
287  * @memberOf _
288  * @since 4.12.0
289  * @category Lang
290  * @param {*} value The value to convert.
291  * @returns {number} Returns the converted number.
292  * @example
293  *
294  * _.toFinite(3.2);
295  * // => 3.2
296  *
297  * _.toFinite(Number.MIN_VALUE);
298  * // => 5e-324
299  *
300  * _.toFinite(Infinity);
301  * // => 1.7976931348623157e+308
302  *
303  * _.toFinite('3.2');
304  * // => 3.2
305  */
306 function toFinite(value) {
307   if (!value) {
308     return value === 0 ? value : 0;
309   }
310   value = toNumber(value);
311   if (value === INFINITY || value === -INFINITY) {
312     var sign = (value < 0 ? -1 : 1);
313     return sign * MAX_INTEGER;
314   }
315   return value === value ? value : 0;
316 }
317
318 /**
319  * Converts `value` to an integer.
320  *
321  * **Note:** This function is loosely based on
322  * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
323  *
324  * @static
325  * @memberOf _
326  * @since 4.0.0
327  * @category Lang
328  * @param {*} value The value to convert.
329  * @returns {number} Returns the converted integer.
330  * @example
331  *
332  * _.toInteger(3.2);
333  * // => 3
334  *
335  * _.toInteger(Number.MIN_VALUE);
336  * // => 0
337  *
338  * _.toInteger(Infinity);
339  * // => 1.7976931348623157e+308
340  *
341  * _.toInteger('3.2');
342  * // => 3
343  */
344 function toInteger(value) {
345   var result = toFinite(value),
346       remainder = result % 1;
347
348   return result === result ? (remainder ? result - remainder : result) : 0;
349 }
350
351 /**
352  * Converts `value` to a number.
353  *
354  * @static
355  * @memberOf _
356  * @since 4.0.0
357  * @category Lang
358  * @param {*} value The value to process.
359  * @returns {number} Returns the number.
360  * @example
361  *
362  * _.toNumber(3.2);
363  * // => 3.2
364  *
365  * _.toNumber(Number.MIN_VALUE);
366  * // => 5e-324
367  *
368  * _.toNumber(Infinity);
369  * // => Infinity
370  *
371  * _.toNumber('3.2');
372  * // => 3.2
373  */
374 function toNumber(value) {
375   if (typeof value == 'number') {
376     return value;
377   }
378   if (isSymbol(value)) {
379     return NAN;
380   }
381   if (isObject(value)) {
382     var other = isFunction(value.valueOf) ? value.valueOf() : value;
383     value = isObject(other) ? (other + '') : other;
384   }
385   if (typeof value != 'string') {
386     return value === 0 ? value : +value;
387   }
388   value = value.replace(reTrim, '');
389   var isBinary = reIsBinary.test(value);
390   return (isBinary || reIsOctal.test(value))
391     ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
392     : (reIsBadHex.test(value) ? NAN : +value);
393 }
394
395 /**
396  * Pads `string` on the left and right sides if it's shorter than `length`.
397  * Padding characters are truncated if they can't be evenly divided by `length`.
398  *
399  * @static
400  * @memberOf _
401  * @since 3.0.0
402  * @category String
403  * @param {string} [string=''] The string to pad.
404  * @param {number} [length=0] The padding length.
405  * @param {string} [chars=' '] The string used as padding.
406  * @returns {string} Returns the padded string.
407  * @example
408  *
409  * _.pad('abc', 8);
410  * // => '  abc   '
411  *
412  * _.pad('abc', 8, '_-');
413  * // => '_-abc_-_'
414  *
415  * _.pad('abc', 3);
416  * // => 'abc'
417  */
418 function pad(string, length, chars) {
419   string = toString(string);
420   length = toInteger(length);
421
422   var strLength = length ? stringSize(string) : 0;
423   if (!length || strLength >= length) {
424     return string;
425   }
426   var mid = (length - strLength) / 2;
427   return (
428     createPadding(nativeFloor(mid), chars) +
429     string +
430     createPadding(nativeCeil(mid), chars)
431   );
432 }
433
434 module.exports = pad;