@telia-ace/widget-utilities 1.0.0

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.
Files changed (111) hide show
  1. package/LICENSE.txt +6 -0
  2. package/README.md +3 -0
  3. package/lib/append-class-names.d.ts +6 -0
  4. package/lib/append-class-names.js +84 -0
  5. package/lib/batch.d.ts +4 -0
  6. package/lib/batch.js +38 -0
  7. package/lib/camilize.d.ts +1 -0
  8. package/lib/camilize.js +29 -0
  9. package/lib/category-trail.d.ts +14 -0
  10. package/lib/category-trail.js +96 -0
  11. package/lib/create-params.d.ts +21 -0
  12. package/lib/create-params.js +108 -0
  13. package/lib/data-uri-to-blob.d.ts +2 -0
  14. package/lib/data-uri-to-blob.js +20 -0
  15. package/lib/debug.d.ts +52 -0
  16. package/lib/debug.js +155 -0
  17. package/lib/deep-clone.d.ts +2 -0
  18. package/lib/deep-clone.js +21 -0
  19. package/lib/find-and-activate-stored-widgets.d.ts +9 -0
  20. package/lib/find-and-activate-stored-widgets.js +27 -0
  21. package/lib/find-category-by-id.d.ts +6 -0
  22. package/lib/find-category-by-id.js +89 -0
  23. package/lib/format-date.d.ts +2 -0
  24. package/lib/format-date.js +23 -0
  25. package/lib/format-url.d.ts +2 -0
  26. package/lib/format-url.js +111 -0
  27. package/lib/get-cookie.d.ts +1 -0
  28. package/lib/get-cookie.js +18 -0
  29. package/lib/has-non-empty-categories.d.ts +2 -0
  30. package/lib/has-non-empty-categories.js +23 -0
  31. package/lib/hash.d.ts +1 -0
  32. package/lib/hash.js +16 -0
  33. package/lib/html-parent-contains.d.ts +7 -0
  34. package/lib/html-parent-contains.js +21 -0
  35. package/lib/index.d.ts +27 -0
  36. package/lib/index.js +57 -0
  37. package/lib/is-anchor-link.d.ts +2 -0
  38. package/lib/is-anchor-link.js +9 -0
  39. package/lib/kebab-case.d.ts +1 -0
  40. package/lib/kebab-case.js +9 -0
  41. package/lib/lock.d.ts +9 -0
  42. package/lib/lock.js +78 -0
  43. package/lib/merge-deep.d.ts +7 -0
  44. package/lib/merge-deep.js +72 -0
  45. package/lib/notify-data-loaded.d.ts +6 -0
  46. package/lib/notify-data-loaded.js +96 -0
  47. package/lib/remove-null-and-undefined-values.d.ts +6 -0
  48. package/lib/remove-null-and-undefined-values.js +12 -0
  49. package/lib/set-cookie.d.ts +1 -0
  50. package/lib/set-cookie.js +12 -0
  51. package/lib/shallow-compare.d.ts +6 -0
  52. package/lib/shallow-compare.js +25 -0
  53. package/lib/uuid.d.ts +1 -0
  54. package/lib/uuid.js +12 -0
  55. package/lib/wait-for.d.ts +20 -0
  56. package/lib/wait-for.js +52 -0
  57. package/lib-esm/append-class-names.d.ts +6 -0
  58. package/lib-esm/append-class-names.js +77 -0
  59. package/lib-esm/batch.d.ts +4 -0
  60. package/lib-esm/batch.js +36 -0
  61. package/lib-esm/camilize.d.ts +1 -0
  62. package/lib-esm/camilize.js +26 -0
  63. package/lib-esm/category-trail.d.ts +14 -0
  64. package/lib-esm/category-trail.js +87 -0
  65. package/lib-esm/create-params.d.ts +21 -0
  66. package/lib-esm/create-params.js +105 -0
  67. package/lib-esm/data-uri-to-blob.d.ts +2 -0
  68. package/lib-esm/data-uri-to-blob.js +18 -0
  69. package/lib-esm/debug.d.ts +52 -0
  70. package/lib-esm/debug.js +151 -0
  71. package/lib-esm/deep-clone.d.ts +2 -0
  72. package/lib-esm/deep-clone.js +19 -0
  73. package/lib-esm/find-and-activate-stored-widgets.d.ts +9 -0
  74. package/lib-esm/find-and-activate-stored-widgets.js +25 -0
  75. package/lib-esm/find-category-by-id.d.ts +6 -0
  76. package/lib-esm/find-category-by-id.js +87 -0
  77. package/lib-esm/format-date.d.ts +2 -0
  78. package/lib-esm/format-date.js +21 -0
  79. package/lib-esm/format-url.d.ts +2 -0
  80. package/lib-esm/format-url.js +109 -0
  81. package/lib-esm/get-cookie.d.ts +1 -0
  82. package/lib-esm/get-cookie.js +15 -0
  83. package/lib-esm/has-non-empty-categories.d.ts +2 -0
  84. package/lib-esm/has-non-empty-categories.js +18 -0
  85. package/lib-esm/hash.d.ts +1 -0
  86. package/lib-esm/hash.js +13 -0
  87. package/lib-esm/html-parent-contains.d.ts +7 -0
  88. package/lib-esm/html-parent-contains.js +19 -0
  89. package/lib-esm/index.d.ts +27 -0
  90. package/lib-esm/index.js +24 -0
  91. package/lib-esm/is-anchor-link.d.ts +2 -0
  92. package/lib-esm/is-anchor-link.js +7 -0
  93. package/lib-esm/kebab-case.d.ts +1 -0
  94. package/lib-esm/kebab-case.js +6 -0
  95. package/lib-esm/lock.d.ts +9 -0
  96. package/lib-esm/lock.js +75 -0
  97. package/lib-esm/merge-deep.d.ts +7 -0
  98. package/lib-esm/merge-deep.js +67 -0
  99. package/lib-esm/notify-data-loaded.d.ts +6 -0
  100. package/lib-esm/notify-data-loaded.js +94 -0
  101. package/lib-esm/remove-null-and-undefined-values.d.ts +6 -0
  102. package/lib-esm/remove-null-and-undefined-values.js +10 -0
  103. package/lib-esm/set-cookie.d.ts +1 -0
  104. package/lib-esm/set-cookie.js +9 -0
  105. package/lib-esm/shallow-compare.d.ts +6 -0
  106. package/lib-esm/shallow-compare.js +23 -0
  107. package/lib-esm/uuid.d.ts +1 -0
  108. package/lib-esm/uuid.js +9 -0
  109. package/lib-esm/wait-for.d.ts +20 -0
  110. package/lib-esm/wait-for.js +50 -0
  111. package/package.json +35 -0
package/LICENSE.txt ADDED
@@ -0,0 +1,6 @@
1
+ Copyright © 2021, Telia Company AB. All rights reserved.
2
+
3
+ THIS PACKAGE AND CONTAINING SOFTWARE IS PART OF
4
+ THE HUMANY SERVICE. BY USING THIS SOFTWARE YOU
5
+ AGREE TO THE FOLLOWING TERMS AND CONDITIONS:
6
+ http://www.humany.com/legal
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@telia-ace/widget-types-grid`
2
+
3
+ The type definition for ACE One Widget (exported as `GridWidget`).
@@ -0,0 +1,6 @@
1
+ declare type ArgumentHandler = string | [boolean, string | string[]] | undefined;
2
+ export declare function uniqueClassArray(classNames: string[]): string[];
3
+ export declare function append(className1?: string, className2?: string): string;
4
+ export declare function handleFunctionArgument(expression: boolean, classes: string | string[]): string | undefined;
5
+ export default function appendClassNames(...args: ArgumentHandler[]): string;
6
+ export {};
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.handleFunctionArgument = exports.append = exports.uniqueClassArray = void 0;
29
+ var _1 = require(".");
30
+ function uniqueClassArray(classNames) {
31
+ var classArray = [];
32
+ classNames.forEach(function (c) {
33
+ if (classArray.indexOf(c) === -1) {
34
+ classArray.push(c);
35
+ }
36
+ });
37
+ return classArray;
38
+ }
39
+ exports.uniqueClassArray = uniqueClassArray;
40
+ function append(className1, className2) {
41
+ if (className1 === void 0) { className1 = ''; }
42
+ if (className2 === void 0) { className2 = ''; }
43
+ var classNames = className1.split(' ').concat(className2.split(' '));
44
+ return uniqueClassArray(classNames).join(' ').trim();
45
+ }
46
+ exports.append = append;
47
+ function handleFunctionArgument(expression, classes) {
48
+ if (Boolean(expression)) {
49
+ if (typeof classes === 'string') {
50
+ return classes;
51
+ }
52
+ if (Array.isArray(classes)) {
53
+ var className_1 = '';
54
+ classes.forEach(function (c) { return (className_1 = append(className_1, c)); });
55
+ return className_1;
56
+ }
57
+ }
58
+ }
59
+ exports.handleFunctionArgument = handleFunctionArgument;
60
+ function appendClassNames() {
61
+ var args = [];
62
+ for (var _i = 0; _i < arguments.length; _i++) {
63
+ args[_i] = arguments[_i];
64
+ }
65
+ var className = '';
66
+ if (args.length) {
67
+ args.forEach(function (argument) {
68
+ if (typeof argument === 'string') {
69
+ className = append(className, argument);
70
+ }
71
+ else if (Array.isArray(argument)) {
72
+ className = append(className, handleFunctionArgument.apply(void 0, __spreadArray([], __read(argument), false)));
73
+ }
74
+ else if (typeof argument !== 'undefined' && argument !== null) {
75
+ if (process.env.NODE_ENV !== 'production') {
76
+ _1.Logger.warn.apply(_1.Logger, __spreadArray(['appendClassNames: arguments either have' +
77
+ 'to be a string or [boolean, ...string[]]. Passed args:'], __read(args), false));
78
+ }
79
+ }
80
+ });
81
+ }
82
+ return className;
83
+ }
84
+ exports.default = appendClassNames;
package/lib/batch.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare type BatchFunction<T> = (acc: T) => T;
2
+ export declare type Batch<T> = (fn: BatchFunction<T>) => Promise<T>;
3
+ declare const createBatch: <T>(delay: number, createFallback: () => T) => Batch<T>;
4
+ export default createBatch;
package/lib/batch.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ var createBatch = function (delay, createFallback) {
20
+ var timeout;
21
+ var queue = [];
22
+ return function (fn) {
23
+ clearTimeout(timeout);
24
+ return new Promise(function (resolve, reject) {
25
+ queue.push([fn, resolve, reject]);
26
+ timeout = setTimeout(function () {
27
+ var acc = createFallback();
28
+ queue.forEach(function (_a) {
29
+ var _b = __read(_a, 3), fn = _b[0], resolve = _b[1], reject = _b[2];
30
+ acc = fn(acc);
31
+ });
32
+ queue = [];
33
+ resolve(acc);
34
+ }, delay);
35
+ });
36
+ };
37
+ };
38
+ exports.default = createBatch;
@@ -0,0 +1 @@
1
+ export default function camilize(obj: any): any;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function camilize(obj) {
4
+ var camilizedObject = {};
5
+ if (typeof obj === 'number' || typeof obj === 'string') {
6
+ return obj;
7
+ }
8
+ for (var prop in obj) {
9
+ if (obj.hasOwnProperty(prop)) {
10
+ var p = obj[prop];
11
+ var camilizedProp = prop.substring(0, 1).toLowerCase() + prop.substring(1);
12
+ if (Object.prototype.toString.call(p) === '[object Array]') {
13
+ camilizedObject[camilizedProp] = [];
14
+ for (var i = 0, c = p.length; i < c; i++) {
15
+ // tslint:disable-line no-increment-decrement
16
+ camilizedObject[camilizedProp].push(camilize(p[i]));
17
+ }
18
+ }
19
+ else if (p !== null && typeof p === 'object') {
20
+ camilizedObject[camilizedProp] = camilize(p);
21
+ }
22
+ else {
23
+ camilizedObject[camilizedProp] = p;
24
+ }
25
+ }
26
+ }
27
+ return camilizedObject;
28
+ }
29
+ exports.default = camilize;
@@ -0,0 +1,14 @@
1
+ import { Container } from '@webprovisions/platform';
2
+ declare type Item = {
3
+ id: string;
4
+ items?: Item[];
5
+ title: string;
6
+ symbol?: any;
7
+ };
8
+ declare type ChildParentStructure = {
9
+ [key: number]: string;
10
+ };
11
+ export declare function categoryTrail(id: string, items: Item[], ids?: string[], structure?: ChildParentStructure): string[];
12
+ export declare const getCategoryTrailAsObjects: (trail: string[], categories: Item[]) => Map<string, Item>;
13
+ export declare const buildCategoryTrail: (routeName: string, categoryIds: string | string[], container: Container, dataType?: 'guide-categories' | 'contact-method-categories') => Promise<any[]>;
14
+ export {};
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildCategoryTrail = exports.getCategoryTrailAsObjects = exports.categoryTrail = void 0;
7
+ var create_params_1 = __importDefault(require("./create-params"));
8
+ var find_category_by_id_1 = __importDefault(require("./find-category-by-id"));
9
+ var format_url_1 = __importDefault(require("./format-url"));
10
+ function childParentStructure(items, structure, parent) {
11
+ if (structure === void 0) { structure = {}; }
12
+ items.forEach(function (item) {
13
+ if (parent) {
14
+ structure[+item.id] = parent;
15
+ }
16
+ if (item.items) {
17
+ childParentStructure(item.items, structure, item.id);
18
+ }
19
+ });
20
+ return structure;
21
+ }
22
+ function categoryTrail(id, items, ids, structure) {
23
+ if (ids === void 0) { ids = [id]; }
24
+ if (structure === void 0) { structure = childParentStructure(items); }
25
+ var addAncestors = function (id) {
26
+ var parentId = structure[+id];
27
+ if (parentId) {
28
+ ids.unshift(parentId);
29
+ addAncestors(parentId);
30
+ }
31
+ };
32
+ var parentId = structure[+id];
33
+ if (parentId) {
34
+ ids.unshift(parentId);
35
+ addAncestors(parentId);
36
+ }
37
+ return ids;
38
+ }
39
+ exports.categoryTrail = categoryTrail;
40
+ var getCategoryTrailAsObjects = function (trail, categories) {
41
+ if (typeof trail === 'undefined' || typeof categories === 'undefined') {
42
+ return new Map();
43
+ }
44
+ return new Map(trail.map(function (categoryId) {
45
+ var category = (0, find_category_by_id_1.default)(categoryId, categories);
46
+ return [categoryId, category];
47
+ }));
48
+ };
49
+ exports.getCategoryTrailAsObjects = getCategoryTrailAsObjects;
50
+ var buildCategoryTrail = function (routeName, categoryIds, container, dataType) {
51
+ if (dataType === void 0) { dataType = 'guide-categories'; }
52
+ return container.getAsync('dataClient').then(function (dataClient) {
53
+ return dataClient
54
+ .fetch(dataType, { expandCategories: 'descendants' })
55
+ .then(function (_a) {
56
+ var categories = _a.categories;
57
+ var buildTrail = function (id) {
58
+ var trail = categoryTrail(id, categories);
59
+ var objectTrail = (0, exports.getCategoryTrailAsObjects)(trail, categories);
60
+ var result = [];
61
+ trail.forEach(function (categoryId) {
62
+ var category = objectTrail.get(categoryId);
63
+ if (category) {
64
+ result.push({
65
+ routeName: routeName,
66
+ title: category.title,
67
+ symbol: category.symbol,
68
+ id: category.id,
69
+ routeParams: dataType === 'contact-method-categories'
70
+ ? (0, create_params_1.default)({
71
+ contactCategory: category.id,
72
+ uriName: (0, format_url_1.default)(category.title),
73
+ })
74
+ : (0, create_params_1.default)({
75
+ guideCategory: category.id,
76
+ uriName: (0, format_url_1.default)(category.title),
77
+ }),
78
+ });
79
+ }
80
+ });
81
+ return result;
82
+ };
83
+ if (Array.isArray(categoryIds)) {
84
+ return categoryIds.reduce(function (acc, id) {
85
+ var result = buildTrail(id);
86
+ if (result.length > 0) {
87
+ acc.push(result);
88
+ }
89
+ return acc;
90
+ }, []);
91
+ }
92
+ return buildTrail(categoryIds);
93
+ });
94
+ });
95
+ };
96
+ exports.buildCategoryTrail = buildCategoryTrail;
@@ -0,0 +1,21 @@
1
+ export declare type Input = {
2
+ phrase?: string;
3
+ category?: ParamValue;
4
+ guideCategory?: ParamValue;
5
+ contactCategory?: ParamValue;
6
+ take?: number;
7
+ connectionKey?: string;
8
+ id?: string;
9
+ uriName?: string;
10
+ sorting?: string;
11
+ tag?: string;
12
+ tagId?: string | number;
13
+ tagTitle?: string;
14
+ } & {
15
+ [key: string]: ParamValue;
16
+ };
17
+ export declare type ParamValue = string | number | any;
18
+ export declare type Params = {
19
+ [key: string]: ParamValue;
20
+ };
21
+ export default function createParams(args?: Input): Params;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ function createParams(args) {
15
+ if (args === void 0) { args = {}; }
16
+ var _a = args.phrase, phrase = _a === void 0 ? '' : _a, category = args.category, guideCategory = args.guideCategory, contactCategory = args.contactCategory, take = args.take, connectionKey = args.connectionKey, accordion = args.accordion, id = args.id, uriName = args.uriName, sorting = args.sorting, tag = args.tag, tagId = args.tagId, tagTitle = args.tagTitle, other = __rest(args, ["phrase", "category", "guideCategory", "contactCategory", "take", "connectionKey", "accordion", "id", "uriName", "sorting", "tag", "tagId", "tagTitle"]);
17
+ var params = {};
18
+ Object.keys(other).forEach(function (k) {
19
+ if (typeof args[k] === 'string') {
20
+ params[k] = args[k];
21
+ }
22
+ });
23
+ if (typeof phrase === 'string' && phrase.length) {
24
+ params.phrase = phrase;
25
+ }
26
+ if (phrase === null) {
27
+ params.phrase = phrase;
28
+ }
29
+ if (typeof guideCategory === 'string' && guideCategory !== '0') {
30
+ params.guideCategory = guideCategory;
31
+ }
32
+ if (typeof guideCategory === 'number' && guideCategory !== 0) {
33
+ params.guideCategory = guideCategory;
34
+ }
35
+ if (typeof guideCategory === 'object' && guideCategory !== null) {
36
+ if (typeof guideCategory.id === 'string' && guideCategory.id !== '0') {
37
+ params.guideCategory = guideCategory.id;
38
+ }
39
+ if (typeof guideCategory.id === 'number' && guideCategory.id !== 0) {
40
+ params.guideCategory = guideCategory.id;
41
+ }
42
+ }
43
+ if (typeof contactCategory === 'string' && contactCategory !== '0') {
44
+ params.contactCategory = contactCategory;
45
+ }
46
+ if (typeof contactCategory === 'number' && contactCategory !== 0) {
47
+ params.contactCategory = contactCategory;
48
+ }
49
+ if (typeof contactCategory === 'object' && contactCategory !== null) {
50
+ if (typeof contactCategory.id === 'string' && contactCategory.id !== '0') {
51
+ params.contactCategory = contactCategory.id;
52
+ }
53
+ if (typeof contactCategory.id === 'number' && contactCategory.id !== 0) {
54
+ params.contactCategory = contactCategory.id;
55
+ }
56
+ }
57
+ if (typeof category === 'string' && category !== '0') {
58
+ params.category = category;
59
+ }
60
+ if (typeof category === 'number' && category !== 0) {
61
+ params.category = category;
62
+ }
63
+ if (typeof category === 'object' && category !== null) {
64
+ if (typeof category.id === 'string' && category.id !== '0') {
65
+ params.category = category.id;
66
+ }
67
+ if (typeof category.id === 'number' && category.id !== 0) {
68
+ params.category = category.id;
69
+ }
70
+ }
71
+ if (id) {
72
+ params.id = id;
73
+ }
74
+ if (uriName &&
75
+ (!!+params.category ||
76
+ !!+params.guideCategory ||
77
+ !!+params.guide ||
78
+ !!+params.contactCategory ||
79
+ !!+params.contactMethod)) {
80
+ params.uriName = uriName;
81
+ }
82
+ if (connectionKey) {
83
+ params.connectionKey = connectionKey;
84
+ }
85
+ if (take) {
86
+ params.take = take;
87
+ }
88
+ if (sorting) {
89
+ params.sorting = sorting;
90
+ }
91
+ if (typeof accordion === 'string' && accordion.length > 0) {
92
+ params.accordion = accordion;
93
+ }
94
+ if (typeof tag === 'string' && tag !== '0') {
95
+ params.tag = tag;
96
+ }
97
+ if (typeof tag === 'number' && tag !== 0) {
98
+ params.tag = tag;
99
+ }
100
+ if (typeof tagId === 'string' || typeof tagId === 'number') {
101
+ params.tagId = tagId;
102
+ }
103
+ if (typeof tagTitle === 'string') {
104
+ params.tagTitle = tagTitle;
105
+ }
106
+ return params;
107
+ }
108
+ exports.default = createParams;
@@ -0,0 +1,2 @@
1
+ declare const dataURItoBlob: (dataURI: string) => Blob;
2
+ export default dataURItoBlob;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var dataURItoBlob = function (dataURI) {
4
+ var byteString;
5
+ var mimestring;
6
+ if (dataURI.split(',')[0].indexOf('base64') !== -1) {
7
+ byteString = atob(dataURI.split(',')[1]);
8
+ }
9
+ else {
10
+ byteString = decodeURI(dataURI.split(',')[1]);
11
+ }
12
+ mimestring = dataURI.split(',')[0].split(':')[1].split(';')[0];
13
+ var content = [];
14
+ for (var i = 0; i < byteString.length; i++) {
15
+ // tslint:disable-line no-increment-decrement
16
+ content[i] = byteString.charCodeAt(i);
17
+ }
18
+ return new Blob([new Uint8Array(content)], { type: mimestring });
19
+ };
20
+ exports.default = dataURItoBlob;
package/lib/debug.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Checks if process.env.NODE_ENV === 'production'
3
+ * and passes arguments to console.warn().
4
+ */
5
+ export declare function debugLog(...args: any[]): false | void;
6
+ /**
7
+ * Simple internal log-handler
8
+ */
9
+ export declare class Logger {
10
+ private keys;
11
+ private lookup;
12
+ /**
13
+ * Passes args to console.log
14
+ */
15
+ static log: (...args: any[]) => void;
16
+ /**
17
+ * Passes args to console.warn
18
+ */
19
+ static warn: (...args: any[]) => void;
20
+ /**
21
+ * Passes args to console.error
22
+ */
23
+ static error: (...args: any[]) => void;
24
+ /**
25
+ * Passes args to console.info
26
+ */
27
+ static info: (...args: any[]) => void;
28
+ /**
29
+ * Checks if key already has been logged.
30
+ * If not, passes following args to console.log
31
+ * and stores key in logged messages.
32
+ */
33
+ log: (key: string, ...args: any[]) => void;
34
+ /**
35
+ * Checks if key already has been logged.
36
+ * If not, passes following args to console.warn
37
+ * and stores key in logged messages.
38
+ */
39
+ warn: (key: string, ...args: any[]) => void;
40
+ /**
41
+ * Checks if key already has been logged.
42
+ * If not, passes following args to console.error
43
+ * and stores key in logged messages.
44
+ */
45
+ error: (key: string, ...args: any[]) => void;
46
+ /**
47
+ * Checks if key already has been logged.
48
+ * If not, passes following args to console.info
49
+ * and stores key in logged messages.
50
+ */
51
+ info: (key: string, ...args: any[]) => void;
52
+ }
package/lib/debug.js ADDED
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.Logger = exports.debugLog = void 0;
29
+ /**
30
+ * Checks if process.env.NODE_ENV === 'production'
31
+ * and passes arguments to console.warn().
32
+ */
33
+ function debugLog() {
34
+ var args = [];
35
+ for (var _i = 0; _i < arguments.length; _i++) {
36
+ args[_i] = arguments[_i];
37
+ }
38
+ return process.env.NODE_ENV !== 'production' && console && console.warn.apply(console, __spreadArray([], __read(args), false));
39
+ }
40
+ exports.debugLog = debugLog;
41
+ var print = function (print, msgOrObj) {
42
+ var args = [];
43
+ for (var _i = 2; _i < arguments.length; _i++) {
44
+ args[_i - 2] = arguments[_i];
45
+ }
46
+ if (typeof msgOrObj === 'string') {
47
+ return print.apply(void 0, __spreadArray(["[humany] ".concat(msgOrObj)], __read(args), false));
48
+ }
49
+ return print.apply(void 0, __spreadArray([msgOrObj], __read(args), false));
50
+ };
51
+ /**
52
+ * Simple internal log-handler
53
+ */
54
+ var Logger = /** @class */ (function () {
55
+ function Logger() {
56
+ var _this = this;
57
+ this.keys = [];
58
+ /**
59
+ * Checks if key already has been logged.
60
+ * If not, passes following args to console.log
61
+ * and stores key in logged messages.
62
+ */
63
+ this.log = function (key) {
64
+ var args = [];
65
+ for (var _i = 1; _i < arguments.length; _i++) {
66
+ args[_i - 1] = arguments[_i];
67
+ }
68
+ return _this.lookup(key, function () { return Logger.log.apply(Logger, __spreadArray([], __read(args), false)); });
69
+ };
70
+ /**
71
+ * Checks if key already has been logged.
72
+ * If not, passes following args to console.warn
73
+ * and stores key in logged messages.
74
+ */
75
+ this.warn = function (key) {
76
+ var args = [];
77
+ for (var _i = 1; _i < arguments.length; _i++) {
78
+ args[_i - 1] = arguments[_i];
79
+ }
80
+ return _this.lookup(key, function () { return Logger.warn.apply(Logger, __spreadArray([], __read(args), false)); });
81
+ };
82
+ /**
83
+ * Checks if key already has been logged.
84
+ * If not, passes following args to console.error
85
+ * and stores key in logged messages.
86
+ */
87
+ this.error = function (key) {
88
+ var args = [];
89
+ for (var _i = 1; _i < arguments.length; _i++) {
90
+ args[_i - 1] = arguments[_i];
91
+ }
92
+ return _this.lookup(key, function () { return Logger.error.apply(Logger, __spreadArray([], __read(args), false)); });
93
+ };
94
+ /**
95
+ * Checks if key already has been logged.
96
+ * If not, passes following args to console.info
97
+ * and stores key in logged messages.
98
+ */
99
+ this.info = function (key) {
100
+ var args = [];
101
+ for (var _i = 1; _i < arguments.length; _i++) {
102
+ args[_i - 1] = arguments[_i];
103
+ }
104
+ return _this.lookup(key, function () { return Logger.info.apply(Logger, __spreadArray([], __read(args), false)); });
105
+ };
106
+ }
107
+ Logger.prototype.lookup = function (key, fn) {
108
+ if (this.keys.indexOf(key) === -1) {
109
+ this.keys.push(key);
110
+ fn();
111
+ }
112
+ };
113
+ /**
114
+ * Passes args to console.log
115
+ */
116
+ Logger.log = function () {
117
+ var args = [];
118
+ for (var _i = 0; _i < arguments.length; _i++) {
119
+ args[_i] = arguments[_i];
120
+ }
121
+ return print.apply(void 0, __spreadArray([console.log], __read(args), false));
122
+ };
123
+ /**
124
+ * Passes args to console.warn
125
+ */
126
+ Logger.warn = function () {
127
+ var args = [];
128
+ for (var _i = 0; _i < arguments.length; _i++) {
129
+ args[_i] = arguments[_i];
130
+ }
131
+ return print.apply(void 0, __spreadArray([console.warn], __read(args), false));
132
+ };
133
+ /**
134
+ * Passes args to console.error
135
+ */
136
+ Logger.error = function () {
137
+ var args = [];
138
+ for (var _i = 0; _i < arguments.length; _i++) {
139
+ args[_i] = arguments[_i];
140
+ }
141
+ return print.apply(void 0, __spreadArray([console.error], __read(args), false));
142
+ };
143
+ /**
144
+ * Passes args to console.info
145
+ */
146
+ Logger.info = function () {
147
+ var args = [];
148
+ for (var _i = 0; _i < arguments.length; _i++) {
149
+ args[_i] = arguments[_i];
150
+ }
151
+ return print.apply(void 0, __spreadArray([console.info], __read(args), false));
152
+ };
153
+ return Logger;
154
+ }());
155
+ exports.Logger = Logger;
@@ -0,0 +1,2 @@
1
+ declare const deepClone: <Type>(data: Type) => Type;
2
+ export default deepClone;