@karta.io/utils 0.21.0 → 0.22.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.cjs +21 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.mjs +21 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const libphonenumberJs = require('libphonenumber-js');
|
|
4
4
|
const lodashEs = require('lodash-es');
|
|
5
|
+
const dayjs = require('dayjs');
|
|
6
|
+
const utc = require('dayjs/plugin/utc');
|
|
7
|
+
const tz = require('dayjs/plugin/timezone');
|
|
8
|
+
const updateLocale = require('dayjs/plugin/updateLocale');
|
|
9
|
+
const isToday = require('dayjs/plugin/isToday');
|
|
5
10
|
const detectBrowser = require('detect-browser');
|
|
6
11
|
|
|
7
12
|
function viewExample(value) {
|
|
@@ -243,6 +248,21 @@ const useClassName = (block) => {
|
|
|
243
248
|
};
|
|
244
249
|
};
|
|
245
250
|
|
|
251
|
+
dayjs.extend(utc);
|
|
252
|
+
dayjs.extend(tz);
|
|
253
|
+
dayjs.extend(updateLocale);
|
|
254
|
+
dayjs.extend(isToday);
|
|
255
|
+
function useDayjs(timezone) {
|
|
256
|
+
dayjs.updateLocale("en", {
|
|
257
|
+
weekStart: 1
|
|
258
|
+
});
|
|
259
|
+
if (!timezone) {
|
|
260
|
+
return dayjs;
|
|
261
|
+
}
|
|
262
|
+
const dayjsExtended = (date, format, locale, strict) => dayjs(date, format, locale, strict).tz(timezone);
|
|
263
|
+
return dayjsExtended;
|
|
264
|
+
}
|
|
265
|
+
|
|
246
266
|
function parseVersion(version) {
|
|
247
267
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
248
268
|
throw new TypeError(
|
|
@@ -304,6 +324,7 @@ exports.isEmptyObject = isEmptyObject;
|
|
|
304
324
|
exports.parsePhone = parsePhone;
|
|
305
325
|
exports.unformatNumber = unformatNumber;
|
|
306
326
|
exports.useClassName = useClassName;
|
|
327
|
+
exports.useDayjs = useDayjs;
|
|
307
328
|
exports.useDetectBrowser = useDetectBrowser;
|
|
308
329
|
exports.validateNumber = validateNumber;
|
|
309
330
|
exports.validatePhone = validatePhone;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
1
2
|
import { Browser } from 'detect-browser';
|
|
2
3
|
|
|
3
4
|
declare function viewExample(value: string): string;
|
|
@@ -94,6 +95,16 @@ declare const useClassName: (block: string) => {
|
|
|
94
95
|
cssVarName: (name: string) => string;
|
|
95
96
|
};
|
|
96
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Обертка над dayjs, позволяющая задавать timezone
|
|
100
|
+
* @see https://day.js.org/en/
|
|
101
|
+
*
|
|
102
|
+
* Использовать параметр timezone нужно крайне аккуратно,
|
|
103
|
+
* может привести к учеткам памяти
|
|
104
|
+
* @todo Подумать как сделать оптимальнее
|
|
105
|
+
*/
|
|
106
|
+
declare function useDayjs(timezone?: string): (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean) => dayjs.Dayjs;
|
|
107
|
+
|
|
97
108
|
interface BrowserInfo {
|
|
98
109
|
isDeprecated?: boolean;
|
|
99
110
|
name?: string;
|
|
@@ -109,4 +120,4 @@ declare function useDetectBrowser(versions: VersionsList, userAgent?: any): Brow
|
|
|
109
120
|
|
|
110
121
|
declare function validatePhone(rule: string, value: string): boolean;
|
|
111
122
|
|
|
112
|
-
export { BrowserInfo, VersionsList, camelizeKeys, createClassName, formatMoney, genLoadingTableRows, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, parsePhone, unformatNumber, useClassName, useDetectBrowser, validateNumber, validatePhone, viewExample };
|
|
123
|
+
export { BrowserInfo, VersionsList, camelizeKeys, createClassName, formatMoney, genLoadingTableRows, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, parsePhone, unformatNumber, useClassName, useDayjs, useDetectBrowser, validateNumber, validatePhone, viewExample };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { parsePhoneNumberFromString } from 'libphonenumber-js';
|
|
2
2
|
import { camelCase } from 'lodash-es';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import utc from 'dayjs/plugin/utc';
|
|
5
|
+
import tz from 'dayjs/plugin/timezone';
|
|
6
|
+
import updateLocale from 'dayjs/plugin/updateLocale';
|
|
7
|
+
import isToday from 'dayjs/plugin/isToday';
|
|
3
8
|
import { detect } from 'detect-browser';
|
|
4
9
|
|
|
5
10
|
function viewExample(value) {
|
|
@@ -241,6 +246,21 @@ const useClassName = (block) => {
|
|
|
241
246
|
};
|
|
242
247
|
};
|
|
243
248
|
|
|
249
|
+
dayjs.extend(utc);
|
|
250
|
+
dayjs.extend(tz);
|
|
251
|
+
dayjs.extend(updateLocale);
|
|
252
|
+
dayjs.extend(isToday);
|
|
253
|
+
function useDayjs(timezone) {
|
|
254
|
+
dayjs.updateLocale("en", {
|
|
255
|
+
weekStart: 1
|
|
256
|
+
});
|
|
257
|
+
if (!timezone) {
|
|
258
|
+
return dayjs;
|
|
259
|
+
}
|
|
260
|
+
const dayjsExtended = (date, format, locale, strict) => dayjs(date, format, locale, strict).tz(timezone);
|
|
261
|
+
return dayjsExtended;
|
|
262
|
+
}
|
|
263
|
+
|
|
244
264
|
function parseVersion(version) {
|
|
245
265
|
if (typeof version !== "string" && typeof version !== "number") {
|
|
246
266
|
throw new TypeError(
|
|
@@ -285,4 +305,4 @@ function validatePhone(rule, value) {
|
|
|
285
305
|
return phoneNumber ? phoneNumber.isValid() : false;
|
|
286
306
|
}
|
|
287
307
|
|
|
288
|
-
export { camelizeKeys, createClassName, formatMoney, genLoadingTableRows, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, parsePhone, unformatNumber, useClassName, useDetectBrowser, validateNumber, validatePhone, viewExample };
|
|
308
|
+
export { camelizeKeys, createClassName, formatMoney, genLoadingTableRows, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, parsePhone, unformatNumber, useClassName, useDayjs, useDetectBrowser, validateNumber, validatePhone, viewExample };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "karta.io utils for admin and application",
|
|
5
5
|
"author": "Vitaly Blokhin <karambafe@gmail.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@karta.io/common-data": "^0.
|
|
23
|
+
"@karta.io/common-data": "^0.22.0",
|
|
24
|
+
"dayjs": "1.11.6",
|
|
24
25
|
"detect-browser": "5.3.0",
|
|
25
26
|
"libphonenumber-js": "1.9.44",
|
|
26
27
|
"lodash-es": "4.17.21"
|