@webalternatif/js-core 1.6.0 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,10 +4,10 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
4
4
  function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
5
5
  function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
6
6
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
7
- import { isArray, isFloat, isInteger, isObject, isPlainObject, isString, isUndefined } from "./is.js";
8
- import { dec2hex, hex2dec, round } from "./math.js";
9
- import { inArray } from "./array.js";
10
- import { each, foreach, map } from "./traversal.js";
7
+ import { isArray, isFloat, isInteger, isPlainObject, isString, isUndefined } from './is.js';
8
+ import { dec2hex, hex2dec, round } from './math.js';
9
+ import { inArray } from './array.js';
10
+ import { each, map } from './traversal.js';
11
11
  // import {translate} from "./Translator.js";
12
12
 
13
13
  export var trim = function trim(str) {
@@ -214,7 +214,9 @@ export var hextorgb = hex2rgb;
214
214
  */
215
215
  export var parse_url = function parse_url(str) {
216
216
  var key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'fragment'],
217
- parser = /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/;
217
+ parser =
218
+ // eslint-disable-next-line no-useless-escape
219
+ /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/;
218
220
  var m = parser.exec(str);
219
221
  var uri = {},
220
222
  i = 14;
@@ -253,45 +255,45 @@ var _addUrlParam = function addUrlParam(url, param) {
253
255
  }
254
256
  var parseUrl = parse_url(url),
255
257
  pos,
256
- hash = "";
257
- if ((pos = url.indexOf("#")) > -1) {
258
+ hash = '';
259
+ if ((pos = url.indexOf('#')) > -1) {
258
260
  hash = url.slice(pos);
259
261
  url = url.slice(0, pos);
260
262
  }
261
263
  var key = encodeURIComponent(param);
262
264
  var val = value === null ? '' : encodeURIComponent(value);
263
265
  if (!parseUrl.query) {
264
- return url + "?" + key + "=" + val + hash;
266
+ return url + '?' + key + '=' + val + hash;
265
267
  }
266
268
  var params = parseUrl.query.split('&');
267
269
  var param_exists = false;
268
270
  for (var i = 0; i < params.length; i++) {
269
- if (params[i].startsWith(key + "=")) {
270
- params[i] = key + "=" + val;
271
+ if (params[i].startsWith(key + '=')) {
272
+ params[i] = key + '=' + val;
271
273
  param_exists = true;
272
274
  break;
273
275
  }
274
276
  }
275
277
  if (!param_exists) {
276
- params.push(key + "=" + val);
278
+ params.push(key + '=' + val);
277
279
  }
278
280
  if (parseUrl.scheme && parseUrl.host) {
279
- return parseUrl.scheme + '://' + parseUrl.host + (parseUrl.path || '') + "?" + params.join("&") + hash;
281
+ return parseUrl.scheme + '://' + parseUrl.host + (parseUrl.path || '') + '?' + params.join('&') + hash;
280
282
  }
281
- return (parseUrl.host || '') + parseUrl.path + "?" + params.join("&") + hash;
283
+ return (parseUrl.host || '') + parseUrl.path + '?' + params.join('&') + hash;
282
284
  };
283
285
  export { _addUrlParam as addUrlParam };
284
286
  export var decodeHtml = function decodeHtml(str) {
285
287
  if (!isString(str)) return '';
286
- return str.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#039;/g, "'");
288
+ return str.replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#039;/g, "'");
287
289
  };
288
290
  export var htmlquotes = function htmlquotes(str) {
289
291
  if (!isString(str)) return '';
290
- return str.replace(/"/g, "&quot;").replace(/'/g, "&#039;");
292
+ return str.replace(/"/g, '&quot;').replace(/'/g, '&#039;');
291
293
  };
292
294
  export var htmlsimplequotes = function htmlsimplequotes(str) {
293
295
  if (!isString(str)) return '';
294
- return str.replace(/'/g, "&#039;");
296
+ return str.replace(/'/g, '&#039;');
295
297
  };
296
298
  export var repeat = function repeat(str, n) {
297
299
  if (!isString(str) || !isFloat(n)) return '';
@@ -303,7 +305,7 @@ export var stripTags = function stripTags(str, tag) {
303
305
  while (rStripTags.test(str)) str = str.replace(rStripTags, '$1');
304
306
  return str;
305
307
  }
306
- return str.replace(/(<([^>]+)>)/ig, "");
308
+ return str.replace(/(<([^>]+)>)/gi, '');
307
309
  };
308
310
  export var toUrl = function toUrl(str) {
309
311
  return trim(noAccent(str).toLowerCase().replace(/[^a-z0-9]/g, '-').replace(/-{2,}/g, '-'), '-');
@@ -313,7 +315,7 @@ export var toUrl = function toUrl(str) {
313
315
  * @see http://stackoverflow.com/questions/3115150/how-to-escape-regular-expression-special-characters-using-javascript
314
316
  */
315
317
  export var escapeRegex = function escapeRegex(str) {
316
- return str.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&").replace(/[\n\t]/g, " ");
318
+ return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&').replace(/[\n\t]/g, ' ');
317
319
  };
318
320
  export var camelCase = function camelCase(str) {
319
321
  if (!str) return '';
@@ -378,7 +380,7 @@ export var f = format;
378
380
  * @see https://stackoverflow.com/questions/7627000/javascript-convert-string-to-safe-class-name-for-css
379
381
  */
380
382
  export var toCssClassName = function toCssClassName(str) {
381
- return str.replace(/[^a-z0-9_-]/ig, function (s) {
383
+ return str.replace(/[^a-z0-9_-]/gi, function (s) {
382
384
  var c = s.charCodeAt(0);
383
385
  if (c === 32) return '-';
384
386
  return '__' + ('000' + c.toString(16)).slice(-4);
@@ -387,7 +389,7 @@ export var toCssClassName = function toCssClassName(str) {
387
389
  export var hilite = function hilite(str, req) {
388
390
  var tag = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'strong';
389
391
  str = decodeHtml(str);
390
- var str_folded = noAccent(str).toLowerCase().replace(/[\[\]]+/g, '');
392
+ var str_folded = noAccent(str).toLowerCase().replace(/[[\]]+/g, '');
391
393
  var q_folded,
392
394
  re,
393
395
  hilite_hints = '';
@@ -397,7 +399,7 @@ export var hilite = function hilite(str, req) {
397
399
  each(req, function (i, q) {
398
400
  if (q.length) {
399
401
  q = decodeHtml(q);
400
- q_folded = noAccent(q).toLowerCase().replace(/[\[\]]+/g, '');
402
+ q_folded = noAccent(q).toLowerCase().replace(/[[\]]+/g, '');
401
403
  re = new RegExp(escapeRegex(q_folded), 'g');
402
404
  hilite_hints = str_folded.replace(re, "[".concat(q_folded, "]"));
403
405
  str_folded = hilite_hints;
@@ -1,5 +1,5 @@
1
- import { foreach } from "./traversal.js";
2
- import * as stringFunctions from "./string.js";
1
+ import { foreach } from './traversal.js';
2
+ import * as stringFunctions from './string.js';
3
3
  foreach(Object.keys(stringFunctions), function (name) {
4
4
  var f = stringFunctions[name],
5
5
  p = String.prototype;
@@ -5,9 +5,9 @@ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
5
5
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
6
6
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
7
7
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
8
- import { isArray, isArrayLike, isBoolean, isObject, isPlainObject, isString, isUndefined } from "./is.js";
9
- import { isWindow } from "./dom.js";
10
- import { sizeOf } from "./utils.js";
8
+ import { isArray, isArrayLike, isBoolean, isObject, isPlainObject, isString, isUndefined } from './is.js';
9
+ import { isWindow } from './dom.js';
10
+ import { sizeOf } from './utils.js';
11
11
 
12
12
  /**
13
13
  * @template T
package/dist/esm/utils.js CHANGED
@@ -1,10 +1,10 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- import { each, map } from "./traversal.js";
3
- import { isArray, isFunction, isObject, isUndefined } from "./is.js";
2
+ import { map } from './traversal.js';
3
+ import { isArray, isObject } from './is.js';
4
4
  var _equals = function equals(o1, o2) {
5
5
  var seen = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakMap();
6
6
  if (o1 === o2) return true;
7
- if (_typeof(o1) !== _typeof(o2) || o1 == null || o2 == null) {
7
+ if (_typeof(o1) !== _typeof(o2) || o1 === null || o2 === null) {
8
8
  return false;
9
9
  }
10
10
  if (isObject(o1)) {
package/docs/array.md ADDED
@@ -0,0 +1,57 @@
1
+ # Array Utilities
2
+
3
+ Description of the array utilities.
4
+
5
+ ## Import
6
+
7
+ ```js
8
+ import { array } from '@webalternatif/js-core'
9
+ ```
10
+
11
+ ---
12
+
13
+ ## API
14
+ <!-- GENERATED:array -->
15
+ <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
16
+
17
+ ## inArray
18
+
19
+ [src/array.js:27-53][1]
20
+
21
+ Checks if a value exists in an array or an object
22
+
23
+ ### Parameters
24
+
25
+ * `value` **any** the searched value
26
+ * `arr` **([Object][2] | [Array][3])** the array
27
+ * `index` **[number][4]** if provided, search from this index (optional, default `0`)
28
+ * `strict` **[boolean][5]** if true, search is done with strict equality (optional, default `false`)
29
+
30
+ ### Examples
31
+
32
+ ```javascript
33
+ inArray(2, [1, 2, 3])
34
+ // → true
35
+ ```
36
+
37
+ ```javascript
38
+ inArray({a: 1}, {a: 1, b: 2})
39
+ // → true
40
+ ```
41
+
42
+ ```javascript
43
+ inArray(5, [1, 2, 3])
44
+ // → false
45
+ ```
46
+
47
+ Returns **[boolean][5]**&#x20;
48
+
49
+ [1]: https://github.com/webalternatif/js-core/blob/c9158e27ed191c37c696ced37950f978a21eecba/src/array.js#L27-L53 "Source code on GitHub"
50
+
51
+ [2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
52
+
53
+ [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
54
+
55
+ [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
56
+
57
+ [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean