@amimpact/willy-utils 4.3.0 → 4.5.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.
package/dist/index.js DELETED
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrap = exports.slugify = exports.readCookie = exports.parseISODuration = exports.observeResize = exports.isValidUrl = exports.isTouchDevice = exports.isPlainObject = exports.isInternalLink = exports.isHoverableDevice = exports.isExternalUrl = exports.isCraftActionUrl = exports.isAsset = exports.getUrlsFromString = exports.getParents = exports.getNestedSet = exports.formatUTCDate = exports.formatNewDate = exports.formatDateFromNow = exports.convertObjectToFormData = exports.formatCraftDate = exports.eraseCookie = exports.downloadFile = exports.createCookie = exports.convertHexToRGBA = exports.checkForScrollbars = exports.capitalize = exports.bytesToSize = exports.$$ = exports.$ = void 0;
4
- var cookie_1 = require("./cookie");
5
- Object.defineProperty(exports, "createCookie", { enumerable: true, get: function () { return cookie_1.createCookie; } });
6
- Object.defineProperty(exports, "readCookie", { enumerable: true, get: function () { return cookie_1.readCookie; } });
7
- Object.defineProperty(exports, "eraseCookie", { enumerable: true, get: function () { return cookie_1.eraseCookie; } });
8
- var date_1 = require("./date");
9
- Object.defineProperty(exports, "formatCraftDate", { enumerable: true, get: function () { return date_1.formatCraftDate; } });
10
- Object.defineProperty(exports, "formatDateFromNow", { enumerable: true, get: function () { return date_1.formatDateFromNow; } });
11
- Object.defineProperty(exports, "formatNewDate", { enumerable: true, get: function () { return date_1.formatNewDate; } });
12
- Object.defineProperty(exports, "formatUTCDate", { enumerable: true, get: function () { return date_1.formatUTCDate; } });
13
- Object.defineProperty(exports, "parseISODuration", { enumerable: true, get: function () { return date_1.parseISODuration; } });
14
- var form_1 = require("./form");
15
- Object.defineProperty(exports, "convertObjectToFormData", { enumerable: true, get: function () { return form_1.convertObjectToFormData; } });
16
- var misc_1 = require("./misc");
17
- Object.defineProperty(exports, "bytesToSize", { enumerable: true, get: function () { return misc_1.bytesToSize; } });
18
- Object.defineProperty(exports, "capitalize", { enumerable: true, get: function () { return misc_1.capitalize; } });
19
- Object.defineProperty(exports, "checkForScrollbars", { enumerable: true, get: function () { return misc_1.checkForScrollbars; } });
20
- Object.defineProperty(exports, "convertHexToRGBA", { enumerable: true, get: function () { return misc_1.convertHexToRGBA; } });
21
- Object.defineProperty(exports, "downloadFile", { enumerable: true, get: function () { return misc_1.downloadFile; } });
22
- Object.defineProperty(exports, "getNestedSet", { enumerable: true, get: function () { return misc_1.getNestedSet; } });
23
- Object.defineProperty(exports, "getUrlsFromString", { enumerable: true, get: function () { return misc_1.getUrlsFromString; } });
24
- Object.defineProperty(exports, "isHoverableDevice", { enumerable: true, get: function () { return misc_1.isHoverableDevice; } });
25
- Object.defineProperty(exports, "isPlainObject", { enumerable: true, get: function () { return misc_1.isPlainObject; } });
26
- Object.defineProperty(exports, "isTouchDevice", { enumerable: true, get: function () { return misc_1.isTouchDevice; } });
27
- Object.defineProperty(exports, "isValidUrl", { enumerable: true, get: function () { return misc_1.isValidUrl; } });
28
- Object.defineProperty(exports, "observeResize", { enumerable: true, get: function () { return misc_1.observeResize; } });
29
- Object.defineProperty(exports, "wrap", { enumerable: true, get: function () { return misc_1.wrap; } });
30
- var selectors_1 = require("./selectors");
31
- Object.defineProperty(exports, "$", { enumerable: true, get: function () { return selectors_1.$; } });
32
- Object.defineProperty(exports, "$$", { enumerable: true, get: function () { return selectors_1.$$; } });
33
- Object.defineProperty(exports, "getParents", { enumerable: true, get: function () { return selectors_1.getParents; } });
34
- var url_1 = require("./url");
35
- Object.defineProperty(exports, "isCraftActionUrl", { enumerable: true, get: function () { return url_1.isCraftActionUrl; } });
36
- Object.defineProperty(exports, "isInternalLink", { enumerable: true, get: function () { return url_1.isInternalLink; } });
37
- Object.defineProperty(exports, "isExternalUrl", { enumerable: true, get: function () { return url_1.isExternalUrl; } });
38
- Object.defineProperty(exports, "isAsset", { enumerable: true, get: function () { return url_1.isAsset; } });
39
- Object.defineProperty(exports, "slugify", { enumerable: true, get: function () { return url_1.slugify; } });
package/dist/misc.d.ts DELETED
@@ -1,94 +0,0 @@
1
- declare global {
2
- interface Navigator {
3
- msSaveBlob?: (blob: any, defaultName?: string) => boolean;
4
- msSaveOrOpenBlob: (blob: any, defaultName?: string) => boolean;
5
- }
6
- }
7
- /**
8
- * Toon mooier bestandsformaat
9
- * @param {string | number} bytes
10
- */
11
- export declare const bytesToSize: (bytes: number) => string;
12
- /**
13
- * Eerste letter van een string een hoofdletter maken
14
- * @param {string} str
15
- */
16
- export declare const capitalize: (str: string) => string;
17
- /**
18
- * Check of een HTML element horizontale of verticale scrollbars heeft
19
- * als dat zo is, dan wordt een class op het element gezet.
20
- *
21
- * @param {HTMLElement} el
22
- * @param {String} dir // vertical of horizontal
23
- */
24
- export declare const checkForScrollbars: (el: HTMLElement, dir?: String) => void;
25
- /**
26
- * Hex kleurcode converten naar rgba
27
- *
28
- * @param {string} hexCode
29
- * @param {number} opacity
30
- */
31
- export declare const convertHexToRGBA: (hexCode: string, opacity?: number) => string;
32
- /**
33
- * Downloaden van een bestand
34
- *
35
- * @param {any} data
36
- * @param {string} fileName
37
- */
38
- export declare const downloadFile: (data: any, fileName: string) => void;
39
- /**
40
- * Flat structure array ombouwen naar een array met children
41
- * @param {array} entries
42
- * @param {number} level
43
- * @param {number | string} left
44
- * @param {number | string} right
45
- */
46
- export declare const getNestedSet: (entries: any[] | undefined, level: number | undefined, left: any, right: any) => any[];
47
- /**
48
- * Urls uit een string halen
49
- * @param {string} content - html
50
- */
51
- export declare const getUrlsFromString: (content: string) => RegExpMatchArray | null;
52
- /**
53
- * Bepalen of jouw device hover ondersteunt
54
- *
55
- * @returns {boolean}
56
- */
57
- export declare const isHoverableDevice: () => boolean;
58
- /**
59
- * Bekijken of een waarde een object is
60
- * https://github.com/reduxjs/redux/blob/master/src/utils/isPlainObject.ts
61
- *
62
- * @param {any} value - Waarde welke je wilt checken of het een object is
63
- * @returns {boolean}
64
- */
65
- export declare const isPlainObject: (value: any) => boolean;
66
- /**
67
- * Bepalen of je gebruikt maakt van een touchscreen
68
- * https://gist.github.com/esedic/39a16a7521d42ae205203e3d40dc19f5
69
- *
70
- * @returns {boolean}
71
- */
72
- export declare const isTouchDevice: () => boolean;
73
- /**
74
- * Bekijken of een waarde url is
75
- *
76
- * @param {any} urlString - Waarde welke je wilt checken of het een url is
77
- * @returns {boolean}
78
- */
79
- export declare const isValidUrl: (urlString: any) => boolean;
80
- /**
81
- * Resize observer; checkt of een HTML element zijn dimensies veranderen
82
- * en zodra dat gebeurt wordt de callback functie gecalled.
83
- *
84
- * @param {HTMLElement} el
85
- * @param {Function} callback
86
- */
87
- export declare const observeResize: (element: HTMLElement, callback: Function) => void;
88
- /**
89
- * Wrap een element in een nieuw element
90
- *
91
- * @param {HTMLElement} el
92
- * @param {HTMLElement} wrapper
93
- */
94
- export declare const wrap: (el: HTMLElement, wrapper: HTMLElement) => void;
package/dist/misc.js DELETED
@@ -1,235 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrap = exports.observeResize = exports.isValidUrl = exports.isTouchDevice = exports.isPlainObject = exports.isHoverableDevice = exports.getUrlsFromString = exports.getNestedSet = exports.downloadFile = exports.convertHexToRGBA = exports.checkForScrollbars = exports.capitalize = exports.bytesToSize = void 0;
4
- /**
5
- * Toon mooier bestandsformaat
6
- * @param {string | number} bytes
7
- */
8
- var bytesToSize = function (bytes) {
9
- if (typeof bytes === 'string') {
10
- bytes = parseInt(bytes);
11
- }
12
- var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
13
- if (bytes === 0)
14
- return '0 Byte';
15
- var i = Math.floor(Math.log(bytes) / Math.log(1024));
16
- return Math.round(bytes / Math.pow(1024, i)) + ' ' + sizes[i];
17
- };
18
- exports.bytesToSize = bytesToSize;
19
- /**
20
- * Eerste letter van een string een hoofdletter maken
21
- * @param {string} str
22
- */
23
- var capitalize = function (str) {
24
- return str.charAt(0).toUpperCase() + str.slice(1);
25
- };
26
- exports.capitalize = capitalize;
27
- /**
28
- * Check of een HTML element horizontale of verticale scrollbars heeft
29
- * als dat zo is, dan wordt een class op het element gezet.
30
- *
31
- * @param {HTMLElement} el
32
- * @param {String} dir // vertical of horizontal
33
- */
34
- var checkForScrollbars = function (el, dir) {
35
- if (dir === void 0) { dir = 'vertical'; }
36
- var direction = dir === 'vertical' ? 'scrollTop' : 'scrollLeft';
37
- var hasScrollbar = !!el[direction];
38
- if (!hasScrollbar) {
39
- el[direction] = 1;
40
- hasScrollbar = !!el[direction];
41
- el[direction] = 0;
42
- }
43
- if (hasScrollbar) {
44
- el.classList.add("has-".concat(dir, "-scrollbar"));
45
- }
46
- else {
47
- el.classList.remove("has-".concat(dir, "-scrollbar"));
48
- }
49
- };
50
- exports.checkForScrollbars = checkForScrollbars;
51
- /**
52
- * Hex kleurcode converten naar rgba
53
- *
54
- * @param {string} hexCode
55
- * @param {number} opacity
56
- */
57
- var convertHexToRGBA = function (hexCode, opacity) {
58
- if (opacity === void 0) { opacity = 1; }
59
- var hex = hexCode.replace('#', '');
60
- if (hex.length === 3) {
61
- hex = "".concat(hex[0]).concat(hex[0]).concat(hex[1]).concat(hex[1]).concat(hex[2]).concat(hex[2]);
62
- }
63
- var r = parseInt(hex.substring(0, 2), 16);
64
- var g = parseInt(hex.substring(2, 4), 16);
65
- var b = parseInt(hex.substring(4, 6), 16);
66
- /* Backward compatibility for whole number based opacity values. */
67
- if (opacity > 1 && opacity <= 100) {
68
- opacity = opacity / 100;
69
- }
70
- return "rgba(".concat(r, ",").concat(g, ",").concat(b, ",").concat(opacity, ")");
71
- };
72
- exports.convertHexToRGBA = convertHexToRGBA;
73
- /**
74
- * Downloaden van een bestand
75
- *
76
- * @param {any} data
77
- * @param {string} fileName
78
- */
79
- var downloadFile = function (data, fileName) {
80
- if (typeof window.navigator.msSaveBlob !== 'undefined') {
81
- window.navigator.msSaveOrOpenBlob(new Blob([data]), fileName);
82
- }
83
- else {
84
- var fileURL = void 0;
85
- if ((0, exports.isValidUrl)(data)) {
86
- fileURL = data;
87
- }
88
- else {
89
- fileURL = window.URL.createObjectURL(new Blob([data]));
90
- }
91
- var fileLink = document.createElement('a');
92
- fileLink.href = fileURL;
93
- fileLink.setAttribute('download', fileName);
94
- document.body.appendChild(fileLink);
95
- fileLink.click();
96
- }
97
- };
98
- exports.downloadFile = downloadFile;
99
- /**
100
- * Flat structure array ombouwen naar een array met children
101
- * @param {array} entries
102
- * @param {number} level
103
- * @param {number | string} left
104
- * @param {number | string} right
105
- */
106
- var getNestedSet = function (entries, level, left, right) {
107
- if (entries === void 0) { entries = []; }
108
- if (level === void 0) { level = 1; }
109
- return entries
110
- .filter(function (item) {
111
- return (parseFloat(item.level) === level &&
112
- ((typeof left === 'undefined' &&
113
- typeof right === 'undefined') ||
114
- (parseFloat(item.lft) > left &&
115
- parseFloat(item.rgt) < right)));
116
- })
117
- .map(function (item) {
118
- var returnItem = item;
119
- returnItem['children'] = (0, exports.getNestedSet)(entries, parseFloat(item.level) + 1, parseFloat(item.lft), parseFloat(item.rgt));
120
- return returnItem;
121
- });
122
- };
123
- exports.getNestedSet = getNestedSet;
124
- /**
125
- * Urls uit een string halen
126
- * @param {string} content - html
127
- */
128
- var getUrlsFromString = function (content) {
129
- var regex = /(https?|ftp|file):\/\/([-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?)/gi;
130
- var m = content.match(regex);
131
- return m || null;
132
- };
133
- exports.getUrlsFromString = getUrlsFromString;
134
- /**
135
- * Bepalen of jouw device hover ondersteunt
136
- *
137
- * @returns {boolean}
138
- */
139
- var isHoverableDevice = function () {
140
- return window.matchMedia('(hover: hover) and (pointer: fine)').matches;
141
- };
142
- exports.isHoverableDevice = isHoverableDevice;
143
- /**
144
- * Bekijken of een waarde een object is
145
- * https://github.com/reduxjs/redux/blob/master/src/utils/isPlainObject.ts
146
- *
147
- * @param {any} value - Waarde welke je wilt checken of het een object is
148
- * @returns {boolean}
149
- */
150
- var isPlainObject = function (value) {
151
- if (typeof value !== 'object' || value === null) {
152
- return false;
153
- }
154
- var proto = value;
155
- while (Object.getPrototypeOf(proto) !== null) {
156
- proto = Object.getPrototypeOf(proto);
157
- }
158
- return Object.getPrototypeOf(value) === proto;
159
- };
160
- exports.isPlainObject = isPlainObject;
161
- /**
162
- * Bepalen of je gebruikt maakt van een touchscreen
163
- * https://gist.github.com/esedic/39a16a7521d42ae205203e3d40dc19f5
164
- *
165
- * @returns {boolean}
166
- */
167
- var isTouchDevice = function () {
168
- var result = false;
169
- if (window.PointerEvent && 'maxTouchPoints' in navigator) {
170
- // if Pointer Events are supported, just check maxTouchPoints
171
- if (navigator.maxTouchPoints > 0) {
172
- result = true;
173
- }
174
- }
175
- else {
176
- // no Pointer Events...
177
- if (window.matchMedia &&
178
- window.matchMedia('(any-pointer:coarse)').matches) {
179
- // check for any-pointer:coarse which mostly means touchscreen
180
- result = true;
181
- }
182
- else if (window.TouchEvent || 'ontouchstart' in window) {
183
- // last resort - check for exposed touch events API / event handler
184
- result = true;
185
- }
186
- }
187
- return result;
188
- };
189
- exports.isTouchDevice = isTouchDevice;
190
- /**
191
- * Bekijken of een waarde url is
192
- *
193
- * @param {any} urlString - Waarde welke je wilt checken of het een url is
194
- * @returns {boolean}
195
- */
196
- var isValidUrl = function (urlString) {
197
- if (typeof urlString !== 'string') {
198
- return false;
199
- }
200
- var urlPattern = new RegExp('^(https?:\\/\\/)?' + // validate protocol
201
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name
202
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // validate OR ip (v4) address
203
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path
204
- '(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string
205
- '(\\#[-a-z\\d_]*)?$', 'i'); // validate fragment locator
206
- return !!urlPattern.test(urlString);
207
- };
208
- exports.isValidUrl = isValidUrl;
209
- /**
210
- * Resize observer; checkt of een HTML element zijn dimensies veranderen
211
- * en zodra dat gebeurt wordt de callback functie gecalled.
212
- *
213
- * @param {HTMLElement} el
214
- * @param {Function} callback
215
- */
216
- var observeResize = function (element, callback) {
217
- var resizeObserver = new ResizeObserver(function () {
218
- callback(element);
219
- });
220
- resizeObserver.observe(element);
221
- };
222
- exports.observeResize = observeResize;
223
- /**
224
- * Wrap een element in een nieuw element
225
- *
226
- * @param {HTMLElement} el
227
- * @param {HTMLElement} wrapper
228
- */
229
- var wrap = function (el, wrapper) {
230
- if (el.parentNode) {
231
- el.parentNode.insertBefore(wrapper, el);
232
- wrapper.appendChild(el);
233
- }
234
- };
235
- exports.wrap = wrap;
@@ -1,24 +0,0 @@
1
- /**
2
- * Selecteer eerste item wat je tegenkomt
3
- *
4
- * @param {string} selector
5
- * @param {*} [containerElement=document] - Element waarin hij moet selecteren
6
- * @returns {(HTMLElement|null)}
7
- */
8
- export declare const $: (selector: string, containerElement?: any) => HTMLElement | null;
9
- /**
10
- * Selecteer alle items
11
- *
12
- * @param {string} selector
13
- * @param {*} [containerElement=document] - Element waarin hij moet selecteren
14
- * @returns {HTMLElement[]}
15
- */
16
- export declare const $$: (selector: string, containerElement?: any) => HTMLElement[];
17
- /**
18
- * Haal parents van een element op
19
- *
20
- * @param {HTMLElement} el - Element waar het om gaat
21
- * @param {string} [parentSelector] - Een selector waar hij aan moet voldoen.
22
- * Als deze niet wordt meegegeven dan geeft hij alle parents terug
23
- */
24
- export declare const getParents: (el: HTMLElement, parentSelector?: string) => HTMLElement[];
package/dist/url.d.ts DELETED
@@ -1,24 +0,0 @@
1
- /**
2
- * Bepalen of een link een intern is, zodat bij Vue apps bijv een router-link gemaakt kan worden
3
- * https://dennisreimann.de/articles/delegating-html-links-to-vue-router.html
4
- *
5
- * @param {string} url
6
- * @param {PointerEvent} ev
7
- */
8
- export declare const isInternalLink: (url: string, ev: PointerEvent) => boolean;
9
- /**
10
- * Bepalen of het om een externe url gaat
11
- */
12
- export declare const isExternalUrl: (url: string) => boolean;
13
- /**
14
- * Bepalen of het om een craft action url gaat
15
- */
16
- export declare const isCraftActionUrl: (url: string) => boolean;
17
- /**
18
- * Checken of url een bestand is, om deze ook in een nieuw venster te openen
19
- */
20
- export declare const isAsset: (url: string) => boolean;
21
- /**
22
- * Maak een slug van een string
23
- */
24
- export declare const slugify: (str: string) => string;
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- // Melding verwijderen 'Module xxx has no default export.'
4
- // https://github.com/Microsoft/TypeScript-React-Starter/issues/8#issuecomment-301265017
5
- "allowSyntheticDefaultImports": true,
6
- "target": "es5",
7
- "module": "commonjs",
8
- "declaration": true,
9
- "outDir": "./dist",
10
- "strict": true,
11
- "suppressImplicitAnyIndexErrors": true,
12
- "lib": [
13
- "es2015",
14
- "es2017",
15
- "es2018",
16
- "dom"
17
- ],
18
- },
19
- "types": ["resize-observer-browser"],
20
- }