PageRenderTime 27ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/simple-jekyll-search/node_modules/karma/node_modules/chokidar/node_modules/fsevents/node_modules/lodash.repeat/index.js

https://gitlab.com/superduperfantastic/blog
JavaScript | 306 lines | 90 code | 23 blank | 193 comment | 32 complexity | 49adde72267b7eca60228547c5d8cf38 MD5 | raw file
  1. /**
  2. * lodash 3.2.0 (Custom Build) <https://lodash.com/>
  3. * Build: `lodash modularize exports="npm" -o ./`
  4. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  5. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  6. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  7. * Available under MIT license <https://lodash.com/license>
  8. */
  9. var root = require('lodash._root');
  10. /** Used as references for various `Number` constants. */
  11. var INFINITY = 1 / 0,
  12. MAX_SAFE_INTEGER = 9007199254740991,
  13. MAX_INTEGER = 1.7976931348623157e+308,
  14. NAN = 0 / 0;
  15. /** `Object#toString` result references. */
  16. var funcTag = '[object Function]',
  17. genTag = '[object GeneratorFunction]',
  18. symbolTag = '[object Symbol]';
  19. /** Used to match leading and trailing whitespace. */
  20. var reTrim = /^\s+|\s+$/g;
  21. /** Used to detect bad signed hexadecimal string values. */
  22. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  23. /** Used to detect binary string values. */
  24. var reIsBinary = /^0b[01]+$/i;
  25. /** Used to detect octal string values. */
  26. var reIsOctal = /^0o[0-7]+$/i;
  27. /** Built-in method references without a dependency on `root`. */
  28. var freeParseInt = parseInt;
  29. /** Used for built-in method references. */
  30. var objectProto = Object.prototype;
  31. /**
  32. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  33. * of values.
  34. */
  35. var objectToString = objectProto.toString;
  36. /** Built-in value references. */
  37. var Symbol = root.Symbol;
  38. /* Built-in method references for those with the same name as other `lodash` methods. */
  39. var nativeFloor = Math.floor;
  40. /** Used to convert symbols to primitives and strings. */
  41. var symbolProto = Symbol ? Symbol.prototype : undefined,
  42. symbolToString = Symbol ? symbolProto.toString : undefined;
  43. /**
  44. * Checks if `value` is classified as a `Function` object.
  45. *
  46. * @static
  47. * @memberOf _
  48. * @category Lang
  49. * @param {*} value The value to check.
  50. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  51. * @example
  52. *
  53. * _.isFunction(_);
  54. * // => true
  55. *
  56. * _.isFunction(/abc/);
  57. * // => false
  58. */
  59. function isFunction(value) {
  60. // The use of `Object#toString` avoids issues with the `typeof` operator
  61. // in Safari 8 which returns 'object' for typed array constructors, and
  62. // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
  63. var tag = isObject(value) ? objectToString.call(value) : '';
  64. return tag == funcTag || tag == genTag;
  65. }
  66. /**
  67. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  68. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  69. *
  70. * @static
  71. * @memberOf _
  72. * @category Lang
  73. * @param {*} value The value to check.
  74. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  75. * @example
  76. *
  77. * _.isObject({});
  78. * // => true
  79. *
  80. * _.isObject([1, 2, 3]);
  81. * // => true
  82. *
  83. * _.isObject(_.noop);
  84. * // => true
  85. *
  86. * _.isObject(null);
  87. * // => false
  88. */
  89. function isObject(value) {
  90. var type = typeof value;
  91. return !!value && (type == 'object' || type == 'function');
  92. }
  93. /**
  94. * Checks if `value` is object-like. A value is object-like if it's not `null`
  95. * and has a `typeof` result of "object".
  96. *
  97. * @static
  98. * @memberOf _
  99. * @category Lang
  100. * @param {*} value The value to check.
  101. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  102. * @example
  103. *
  104. * _.isObjectLike({});
  105. * // => true
  106. *
  107. * _.isObjectLike([1, 2, 3]);
  108. * // => true
  109. *
  110. * _.isObjectLike(_.noop);
  111. * // => false
  112. *
  113. * _.isObjectLike(null);
  114. * // => false
  115. */
  116. function isObjectLike(value) {
  117. return !!value && typeof value == 'object';
  118. }
  119. /**
  120. * Checks if `value` is classified as a `Symbol` primitive or object.
  121. *
  122. * @static
  123. * @memberOf _
  124. * @category Lang
  125. * @param {*} value The value to check.
  126. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  127. * @example
  128. *
  129. * _.isSymbol(Symbol.iterator);
  130. * // => true
  131. *
  132. * _.isSymbol('abc');
  133. * // => false
  134. */
  135. function isSymbol(value) {
  136. return typeof value == 'symbol' ||
  137. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  138. }
  139. /**
  140. * Converts `value` to an integer.
  141. *
  142. * **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
  143. *
  144. * @static
  145. * @memberOf _
  146. * @category Lang
  147. * @param {*} value The value to convert.
  148. * @returns {number} Returns the converted integer.
  149. * @example
  150. *
  151. * _.toInteger(3);
  152. * // => 3
  153. *
  154. * _.toInteger(Number.MIN_VALUE);
  155. * // => 0
  156. *
  157. * _.toInteger(Infinity);
  158. * // => 1.7976931348623157e+308
  159. *
  160. * _.toInteger('3');
  161. * // => 3
  162. */
  163. function toInteger(value) {
  164. if (!value) {
  165. return value === 0 ? value : 0;
  166. }
  167. value = toNumber(value);
  168. if (value === INFINITY || value === -INFINITY) {
  169. var sign = (value < 0 ? -1 : 1);
  170. return sign * MAX_INTEGER;
  171. }
  172. var remainder = value % 1;
  173. return value === value ? (remainder ? value - remainder : value) : 0;
  174. }
  175. /**
  176. * Converts `value` to a number.
  177. *
  178. * @static
  179. * @memberOf _
  180. * @category Lang
  181. * @param {*} value The value to process.
  182. * @returns {number} Returns the number.
  183. * @example
  184. *
  185. * _.toNumber(3);
  186. * // => 3
  187. *
  188. * _.toNumber(Number.MIN_VALUE);
  189. * // => 5e-324
  190. *
  191. * _.toNumber(Infinity);
  192. * // => Infinity
  193. *
  194. * _.toNumber('3');
  195. * // => 3
  196. */
  197. function toNumber(value) {
  198. if (isObject(value)) {
  199. var other = isFunction(value.valueOf) ? value.valueOf() : value;
  200. value = isObject(other) ? (other + '') : other;
  201. }
  202. if (typeof value != 'string') {
  203. return value === 0 ? value : +value;
  204. }
  205. value = value.replace(reTrim, '');
  206. var isBinary = reIsBinary.test(value);
  207. return (isBinary || reIsOctal.test(value))
  208. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  209. : (reIsBadHex.test(value) ? NAN : +value);
  210. }
  211. /**
  212. * Converts `value` to a string if it's not one. An empty string is returned
  213. * for `null` and `undefined` values. The sign of `-0` is preserved.
  214. *
  215. * @static
  216. * @memberOf _
  217. * @category Lang
  218. * @param {*} value The value to process.
  219. * @returns {string} Returns the string.
  220. * @example
  221. *
  222. * _.toString(null);
  223. * // => ''
  224. *
  225. * _.toString(-0);
  226. * // => '-0'
  227. *
  228. * _.toString([1, 2, 3]);
  229. * // => '1,2,3'
  230. */
  231. function toString(value) {
  232. // Exit early for strings to avoid a performance hit in some environments.
  233. if (typeof value == 'string') {
  234. return value;
  235. }
  236. if (value == null) {
  237. return '';
  238. }
  239. if (isSymbol(value)) {
  240. return Symbol ? symbolToString.call(value) : '';
  241. }
  242. var result = (value + '');
  243. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  244. }
  245. /**
  246. * Repeats the given string `n` times.
  247. *
  248. * @static
  249. * @memberOf _
  250. * @category String
  251. * @param {string} [string=''] The string to repeat.
  252. * @param {number} [n=0] The number of times to repeat the string.
  253. * @returns {string} Returns the repeated string.
  254. * @example
  255. *
  256. * _.repeat('*', 3);
  257. * // => '***'
  258. *
  259. * _.repeat('abc', 2);
  260. * // => 'abcabc'
  261. *
  262. * _.repeat('abc', 0);
  263. * // => ''
  264. */
  265. function repeat(string, n) {
  266. string = toString(string);
  267. n = toInteger(n);
  268. var result = '';
  269. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  270. return result;
  271. }
  272. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  273. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  274. do {
  275. if (n % 2) {
  276. result += string;
  277. }
  278. n = nativeFloor(n / 2);
  279. string += string;
  280. } while (n);
  281. return result;
  282. }
  283. module.exports = repeat;