@amimpact/willy-utils 1.3.5 → 1.3.8-beta.1
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/date.d.ts +14 -0
- package/dist/date.js +21 -11
- package/dist/misc.d.ts +15 -7
- package/dist/misc.js +37 -20
- package/package.json +8 -7
package/dist/date.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ interface FormatCraftDateOptions {
|
|
|
17
17
|
* @memberof FormatCraftDateOptions
|
|
18
18
|
*/
|
|
19
19
|
format: string;
|
|
20
|
+
/**
|
|
21
|
+
* i18n Locale mee kunnen geven
|
|
22
|
+
*
|
|
23
|
+
* @type {string}
|
|
24
|
+
* @memberof FormatCraftDateOptions
|
|
25
|
+
*/
|
|
26
|
+
locale: string;
|
|
20
27
|
/**
|
|
21
28
|
* Amerikaans formaat maken om in Craft op te kunnen slaan, anders Nederlands
|
|
22
29
|
*
|
|
@@ -79,6 +86,13 @@ interface FormatDateFromNowOptions {
|
|
|
79
86
|
* @memberof FormatDateFromNowOptions
|
|
80
87
|
*/
|
|
81
88
|
strict: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Welke locale is default
|
|
91
|
+
*
|
|
92
|
+
* @type {any}
|
|
93
|
+
* @memberof FormatDateFromNowOptions
|
|
94
|
+
*/
|
|
95
|
+
locale: any;
|
|
82
96
|
}
|
|
83
97
|
/**
|
|
84
98
|
* Opties voor parseISODuration
|
package/dist/date.js
CHANGED
|
@@ -8,8 +8,16 @@ var formatDuration_1 = require("date-fns/formatDuration");
|
|
|
8
8
|
var isBefore_1 = require("date-fns/isBefore");
|
|
9
9
|
var subDays_1 = require("date-fns/subDays");
|
|
10
10
|
var locale_1 = require("date-fns/locale");
|
|
11
|
-
var
|
|
11
|
+
var date_fns_tz_1 = require("date-fns-tz");
|
|
12
12
|
var tinyduration_1 = require("./includes/tinyduration");
|
|
13
|
+
/**
|
|
14
|
+
* Momenteel beschikbare locales
|
|
15
|
+
* Engels is default (leeg)
|
|
16
|
+
*/
|
|
17
|
+
var availableLocales = {
|
|
18
|
+
en: '',
|
|
19
|
+
nl: locale_1.nl,
|
|
20
|
+
};
|
|
13
21
|
/**
|
|
14
22
|
* Format date object uit Craft naar iets leesbaars
|
|
15
23
|
*
|
|
@@ -18,6 +26,7 @@ var tinyduration_1 = require("./includes/tinyduration");
|
|
|
18
26
|
*/
|
|
19
27
|
exports.formatCraftDate = function (dateObject, options) {
|
|
20
28
|
var dateFormat = options && options.systemFormat ? 'yyyy-MM-dd' : 'dd-MM-yyyy';
|
|
29
|
+
var localeString = 'nl';
|
|
21
30
|
if (options && options.showTime) {
|
|
22
31
|
dateFormat += ' HH:mm';
|
|
23
32
|
}
|
|
@@ -25,6 +34,10 @@ exports.formatCraftDate = function (dateObject, options) {
|
|
|
25
34
|
if (options && options.format) {
|
|
26
35
|
dateFormat = options.format;
|
|
27
36
|
}
|
|
37
|
+
// Locale mee kunnen geven
|
|
38
|
+
if (options && options.locale) {
|
|
39
|
+
localeString = options.locale;
|
|
40
|
+
}
|
|
28
41
|
if (!dateObject || !dateObject.date) {
|
|
29
42
|
return '';
|
|
30
43
|
}
|
|
@@ -36,7 +49,7 @@ exports.formatCraftDate = function (dateObject, options) {
|
|
|
36
49
|
var dateToFormat = dateObject.date.replace(/-/g, '/').split('.')[0];
|
|
37
50
|
// De spatie tussen datum en tijd vervangen door 'T', anders snapt IE het niet
|
|
38
51
|
return format_1.default(new Date(dateToFormat), dateFormat, {
|
|
39
|
-
locale:
|
|
52
|
+
locale: availableLocales[localeString],
|
|
40
53
|
});
|
|
41
54
|
};
|
|
42
55
|
/**
|
|
@@ -51,6 +64,7 @@ exports.formatDateFromNow = function (dateObject, options) {
|
|
|
51
64
|
showDateForOldFormat: 'dd-MM-yyyy',
|
|
52
65
|
numberOfDaysShowDateForOld: 7,
|
|
53
66
|
strict: false,
|
|
67
|
+
locale: locale_1.nl,
|
|
54
68
|
};
|
|
55
69
|
var opts = defaultOptions;
|
|
56
70
|
if (options) {
|
|
@@ -59,23 +73,21 @@ exports.formatDateFromNow = function (dateObject, options) {
|
|
|
59
73
|
if (!dateObject || !dateObject.date) {
|
|
60
74
|
return '';
|
|
61
75
|
}
|
|
62
|
-
var parsed =
|
|
63
|
-
timeZone: dateObject.timezone,
|
|
64
|
-
});
|
|
76
|
+
var parsed = date_fns_tz_1.zonedTimeToUtc(dateObject.date, dateObject.timezone);
|
|
65
77
|
/**
|
|
66
78
|
* Datum tonen voor ouder dan x tijd
|
|
67
79
|
*/
|
|
68
80
|
if (opts.showDateForOld &&
|
|
69
81
|
isBefore_1.default(parsed, subDays_1.default(new Date(), opts.numberOfDaysShowDateForOld))) {
|
|
70
82
|
return format_1.default(new Date(dateObject.date.replace(' ', 'T')), opts.showDateForOldFormat, {
|
|
71
|
-
locale:
|
|
83
|
+
locale: availableLocales[opts.locale],
|
|
72
84
|
});
|
|
73
85
|
}
|
|
74
86
|
else {
|
|
75
87
|
var formatDistanceOptions = {
|
|
76
88
|
includeSeconds: opts.includeSeconds,
|
|
77
89
|
addSuffix: opts.addSuffix,
|
|
78
|
-
locale:
|
|
90
|
+
locale: availableLocales[opts.locale],
|
|
79
91
|
};
|
|
80
92
|
/**
|
|
81
93
|
* De postdate moet bepaald worden met timezone erbij. Anders krijg je in Engeland bijv de melding 'over ongeveer een uur'
|
|
@@ -102,10 +114,8 @@ exports.formatNewDate = function (dateObject) {
|
|
|
102
114
|
* Safari begrijpt dit niet en geeft dan een NaN met new Date(date)
|
|
103
115
|
* Safari begrijpt het wel als alle - vervangen worden door /, en het laatste gedeelte achter de punt weg is
|
|
104
116
|
*/
|
|
105
|
-
|
|
106
|
-
var parsed =
|
|
107
|
-
timeZone: dateObject.timezone,
|
|
108
|
-
});
|
|
117
|
+
// const dateString = dateObject.date.replace(/-/g, '/').split('.')[0];
|
|
118
|
+
var parsed = date_fns_tz_1.zonedTimeToUtc(dateObject.date, dateObject.timezone);
|
|
109
119
|
return new Date(parsed);
|
|
110
120
|
};
|
|
111
121
|
/**
|
package/dist/misc.d.ts
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
* @param {string | number} bytes
|
|
4
4
|
*/
|
|
5
5
|
export declare const bytesToSize: (bytes: number) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Downloaden van een bestand
|
|
8
|
+
*
|
|
9
|
+
* @param {any} data
|
|
10
|
+
* @param {string} fileName
|
|
11
|
+
*/
|
|
12
|
+
export declare const downloadFile: (data: any, fileName: string) => void;
|
|
6
13
|
/**
|
|
7
14
|
* Flat structure array ombouwen naar een array met children
|
|
8
15
|
* @param {array} entries
|
|
@@ -16,6 +23,14 @@ export declare const getNestedSet: (entries: any[] | undefined, level: number |
|
|
|
16
23
|
* @param {string} content - html
|
|
17
24
|
*/
|
|
18
25
|
export declare const getUrlsFromString: (content: string) => RegExpMatchArray | null;
|
|
26
|
+
/**
|
|
27
|
+
* Bekijken of een waarde een object is
|
|
28
|
+
* https://github.com/reduxjs/redux/blob/master/src/utils/isPlainObject.ts
|
|
29
|
+
*
|
|
30
|
+
* @param {any} value - Waarde welke je wilt checken of het een object is
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
*/
|
|
33
|
+
export declare const isPlainObject: (value: any) => boolean;
|
|
19
34
|
/**
|
|
20
35
|
* Wrap een element in een nieuw element
|
|
21
36
|
*
|
|
@@ -23,10 +38,3 @@ export declare const getUrlsFromString: (content: string) => RegExpMatchArray |
|
|
|
23
38
|
* @param {HTMLElement} wrapper
|
|
24
39
|
*/
|
|
25
40
|
export declare const wrap: (el: HTMLElement, wrapper: HTMLElement) => void;
|
|
26
|
-
/**
|
|
27
|
-
* Downloaden van een bestand
|
|
28
|
-
*
|
|
29
|
-
* @param {any} data
|
|
30
|
-
* @param {string} fileName
|
|
31
|
-
*/
|
|
32
|
-
export declare const downloadFile: (data: any, fileName: string) => void;
|
package/dist/misc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.wrap = exports.isPlainObject = exports.getUrlsFromString = exports.getNestedSet = exports.downloadFile = exports.bytesToSize = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Toon mooier bestandsformaat
|
|
6
6
|
* @param {string | number} bytes
|
|
@@ -15,6 +15,25 @@ exports.bytesToSize = function (bytes) {
|
|
|
15
15
|
var i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
16
16
|
return Math.round(bytes / Math.pow(1024, i)) + ' ' + sizes[i];
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Downloaden van een bestand
|
|
20
|
+
*
|
|
21
|
+
* @param {any} data
|
|
22
|
+
* @param {string} fileName
|
|
23
|
+
*/
|
|
24
|
+
exports.downloadFile = function (data, fileName) {
|
|
25
|
+
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
|
26
|
+
window.navigator.msSaveOrOpenBlob(new Blob([data]), fileName);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
var fileURL = window.URL.createObjectURL(new Blob([data]));
|
|
30
|
+
var fileLink = document.createElement('a');
|
|
31
|
+
fileLink.href = fileURL;
|
|
32
|
+
fileLink.setAttribute('download', fileName);
|
|
33
|
+
document.body.appendChild(fileLink);
|
|
34
|
+
fileLink.click();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
18
37
|
/**
|
|
19
38
|
* Flat structure array ombouwen naar een array met children
|
|
20
39
|
* @param {array} entries
|
|
@@ -48,6 +67,23 @@ exports.getUrlsFromString = function (content) {
|
|
|
48
67
|
var m = content.match(regex);
|
|
49
68
|
return m || null;
|
|
50
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Bekijken of een waarde een object is
|
|
72
|
+
* https://github.com/reduxjs/redux/blob/master/src/utils/isPlainObject.ts
|
|
73
|
+
*
|
|
74
|
+
* @param {any} value - Waarde welke je wilt checken of het een object is
|
|
75
|
+
* @returns {boolean}
|
|
76
|
+
*/
|
|
77
|
+
exports.isPlainObject = function (value) {
|
|
78
|
+
if (typeof value !== 'object' || value === null) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
var proto = value;
|
|
82
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
83
|
+
proto = Object.getPrototypeOf(proto);
|
|
84
|
+
}
|
|
85
|
+
return Object.getPrototypeOf(value) === proto;
|
|
86
|
+
};
|
|
51
87
|
/**
|
|
52
88
|
* Wrap een element in een nieuw element
|
|
53
89
|
*
|
|
@@ -60,22 +96,3 @@ exports.wrap = function (el, wrapper) {
|
|
|
60
96
|
wrapper.appendChild(el);
|
|
61
97
|
}
|
|
62
98
|
};
|
|
63
|
-
/**
|
|
64
|
-
* Downloaden van een bestand
|
|
65
|
-
*
|
|
66
|
-
* @param {any} data
|
|
67
|
-
* @param {string} fileName
|
|
68
|
-
*/
|
|
69
|
-
exports.downloadFile = function (data, fileName) {
|
|
70
|
-
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
|
71
|
-
window.navigator.msSaveOrOpenBlob(new Blob([data]), fileName);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
var fileURL = window.URL.createObjectURL(new Blob([data]));
|
|
75
|
-
var fileLink = document.createElement('a');
|
|
76
|
-
fileLink.href = fileURL;
|
|
77
|
-
fileLink.setAttribute('download', fileName);
|
|
78
|
-
document.body.appendChild(fileLink);
|
|
79
|
-
fileLink.click();
|
|
80
|
-
}
|
|
81
|
-
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amimpact/willy-utils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8-beta.1",
|
|
4
4
|
"description": "Javascript utils",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"publish:
|
|
10
|
-
"publish:
|
|
11
|
-
"publish:
|
|
9
|
+
"publish:prerelease": "npm version prerelease --preid beta && npm publish --tag beta",
|
|
10
|
+
"publish:prepatch": "npm version prepatch --preid beta && npm publish --tag beta",
|
|
11
|
+
"publish:patch": "npm version patch && npm publish",
|
|
12
|
+
"publish:preminor": "npm version preminor --preid beta && npm publish --tag beta",
|
|
13
|
+
"publish:minor": "npm version minor && npm publish",
|
|
12
14
|
"postpublish": "git push origin --all; git push origin --tags",
|
|
13
|
-
"postversion": "npm publish",
|
|
14
15
|
"preversion": "npm run build",
|
|
15
16
|
"watch": "onchange src/* -- npm run build"
|
|
16
17
|
},
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"typescript": "4.0.5"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"date-fns": "2.
|
|
35
|
-
"date-fns-
|
|
35
|
+
"date-fns": "2.27.0",
|
|
36
|
+
"date-fns-tz": "1.1.6"
|
|
36
37
|
}
|
|
37
38
|
}
|