@karta.io/utils 0.33.6 → 0.33.8

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const camelCase = require('lodash/camelCase.js');
4
+ const commonData = require('@karta.io/common-data');
4
5
  const libphonenumberJs = require('libphonenumber-js');
5
6
  const snakeCase = require('lodash/snakeCase.js');
6
7
  const vue = require('vue');
@@ -37,18 +38,18 @@ function createClassName(className) {
37
38
  }(className);
38
39
  }
39
40
 
40
- function formatMoney(value, currency, options = { locale: "en-US", minimumFractionDigits: 2, maximumFractionDigits: 2 }) {
41
+ function formatMoney(value, currency = commonData.CURRENCY_DEFAULT, options = {}) {
41
42
  let convertedValue = Number(value);
42
43
  if (value === null || Number.isNaN(convertedValue)) {
43
44
  return "";
44
45
  }
45
- const formatter = new Intl.NumberFormat(options.locale, {
46
- minimumFractionDigits: options.minimumFractionDigits,
47
- maximumFractionDigits: options.maximumFractionDigits,
48
- ...currency && {
49
- style: "currency",
50
- currency
51
- }
46
+ const { locale = "en-US", ...otherOptions } = options;
47
+ const formatter = new Intl.NumberFormat(locale, {
48
+ style: "currency",
49
+ currency,
50
+ minimumFractionDigits: 2,
51
+ maximumFractionDigits: 2,
52
+ ...otherOptions
52
53
  });
53
54
  return formatter.format(convertedValue);
54
55
  }
package/dist/index.d.ts CHANGED
@@ -5,196 +5,195 @@ import { Browser } from 'detect-browser';
5
5
  import logdown from 'logdown';
6
6
  import { RuleItem } from 'async-validator';
7
7
 
8
- interface Dictionary {
9
- [keys: string | number]: any;
10
- }
11
- interface ResponseError {
12
- status: number;
13
- statusMessage: string;
14
- message: string;
15
- data: Record<string, string | string[]> | null;
8
+ interface Dictionary {
9
+ [keys: string | number]: any;
10
+ }
11
+ interface ResponseError {
12
+ status: number;
13
+ statusMessage: string;
14
+ message: string;
15
+ data: Record<string, string | string[]> | null;
16
16
  }
17
17
 
18
18
  declare function camelizeKeys(object: Dictionary): Dictionary;
19
19
 
20
20
  declare function createClassName(className: string): (...classNames: string[]) => string;
21
21
 
22
- declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: {
23
- locale: string;
24
- minimumFractionDigits: number;
25
- maximumFractionDigits: number;
26
- }): string;
22
+ interface Options$2 extends Intl.NumberFormatOptions {
23
+ locale?: string;
24
+ }
25
+ declare function formatMoney(value: string | number | null | undefined, currency?: string, options?: Options$2): string;
27
26
 
28
- declare function genLoadingTableRows(columns: Dictionary[], limit: number): {
29
- id: number | undefined;
30
- key?: undefined;
27
+ declare function genLoadingTableRows(columns: Dictionary[], limit: number): {
28
+ id: number | undefined;
29
+ key?: undefined;
31
30
  }[];
32
31
 
33
32
  declare function genRandomNumber(min: number, max: number): number;
34
33
 
35
34
  declare function genUUID(): string;
36
35
 
37
- interface Options$1 {
38
- hasOnlyLast4: boolean;
39
- isHidden: boolean;
40
- dot: string;
41
- }
36
+ interface Options$1 {
37
+ hasOnlyLast4: boolean;
38
+ isHidden: boolean;
39
+ dot: string;
40
+ }
42
41
  declare function getCardNumber(number: string, options?: Partial<Options$1>): string;
43
42
 
44
43
  declare function getCountryFromPhone(phone: string): string;
45
44
 
46
- declare function isElementIgnored({ ignoredClasses, event, }?: {
47
- ignoredClasses?: string[];
48
- event?: Event;
45
+ declare function isElementIgnored({ ignoredClasses, event, }?: {
46
+ ignoredClasses?: string[];
47
+ event?: Event;
49
48
  }): boolean;
50
49
 
51
50
  declare function isEmptyObject(object: {}): boolean;
52
51
 
53
- declare function getPaginationParams({ page, limit, }: {
54
- page: string | number;
55
- limit: string | number;
56
- }): {
57
- limit: number;
58
- offset: number;
59
- };
60
- declare function getPaginationLimit({ limit, }: {
61
- limit: string | number;
62
- }): number;
63
- declare function getPaginationOffset({ page, limit, }: {
64
- page: string | number;
65
- limit: string | number;
66
- }): number;
67
- declare function getPaginationPages({ count, limit, }: {
68
- count: number;
69
- limit: string | number;
52
+ declare function getPaginationParams({ page, limit, }: {
53
+ page: string | number;
54
+ limit: string | number;
55
+ }): {
56
+ limit: number;
57
+ offset: number;
58
+ };
59
+ declare function getPaginationLimit({ limit, }: {
60
+ limit: string | number;
61
+ }): number;
62
+ declare function getPaginationOffset({ page, limit, }: {
63
+ page: string | number;
64
+ limit: string | number;
65
+ }): number;
66
+ declare function getPaginationPages({ count, limit, }: {
67
+ count: number;
68
+ limit: string | number;
70
69
  }): number;
71
70
 
72
71
  declare function parsePhone(phone: string | null | undefined): string;
73
72
 
74
- type SnakelizeKeysProp = Record<string | number, any>;
73
+ type SnakelizeKeysProp = Record<string | number, any>;
75
74
  declare function snakelizeKeys(prop: SnakelizeKeysProp): SnakelizeKeysProp;
76
75
 
77
- /**
78
- * Принимает на вход число в виде строки или числа,
79
- * возвращает корректное значение типа Number (убирает лишние пробелы и запятые)
80
- * @example
81
- * // returns 1000
82
- * unformatNumber('1 000');
83
- * @example
84
- * // returns 1000
85
- * unformatNumber('1,000')
86
- * @example
87
- * // returns 1000.123
88
- * unformatNummber('1 000,123')
89
- * @example
90
- * // returns 1000.123
91
- * unformatNummber('1,000.123')
92
- * @param value
93
- * @return number
94
- */
76
+ /**
77
+ * Принимает на вход число в виде строки или числа,
78
+ * возвращает корректное значение типа Number (убирает лишние пробелы и запятые)
79
+ * @example
80
+ * // returns 1000
81
+ * unformatNumber('1 000');
82
+ * @example
83
+ * // returns 1000
84
+ * unformatNumber('1,000')
85
+ * @example
86
+ * // returns 1000.123
87
+ * unformatNummber('1 000,123')
88
+ * @example
89
+ * // returns 1000.123
90
+ * unformatNummber('1,000.123')
91
+ * @param value
92
+ * @return number
93
+ */
95
94
  declare function unformatNumber(value: string | number): string | number;
96
95
 
97
96
  declare function validateNumber(value: string | number, defaultValue: number): number;
98
97
 
99
- interface UiComponentsResolverOptions {
100
- prefix?: string;
101
- }
98
+ interface UiComponentsResolverOptions {
99
+ prefix?: string;
100
+ }
102
101
  declare function UiComponentsResolver(options?: UiComponentsResolverOptions): any;
103
102
 
104
- declare function useAbortController<T extends (...args: any[]) => any>(callback: T): {
105
- call(...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
106
- abort(): void;
107
- isAborted(error: ResponseError): boolean;
103
+ declare function useAbortController<T extends (...args: any[]) => any>(callback: T): {
104
+ call(...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
105
+ abort(): void;
106
+ isAborted(error: ResponseError): boolean;
108
107
  };
109
108
 
110
- declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, selectedValues, params, }: {
111
- apiMethod: T;
112
- mapResultCallback: K;
113
- selectedValues: ComputedRef<Parameters<T>[0]['includedIds']> | WritableComputedRef<Parameters<T>[0]['includedIds']>;
114
- params?: Parameters<T>[0];
115
- }): {
116
- search: vue.Ref<string>;
117
- options: ComputedRef<ReturnType<K>[1][]>;
118
- loading: vue.Ref<boolean>;
119
- hasNextPage: ComputedRef<boolean>;
120
- items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
121
- loadItems: (isSearch?: boolean) => Promise<void>;
122
- handleSearch: (value: string) => Promise<void>;
109
+ declare function useAsyncMultiselect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, selectedValues, params, }: {
110
+ apiMethod: T;
111
+ mapResultCallback: K;
112
+ selectedValues: ComputedRef<Parameters<T>[0]['includedIds']> | WritableComputedRef<Parameters<T>[0]['includedIds']>;
113
+ params?: Parameters<T>[0];
114
+ }): {
115
+ search: vue.Ref<string>;
116
+ options: ComputedRef<ReturnType<K>[1][]>;
117
+ loading: vue.Ref<boolean>;
118
+ hasNextPage: ComputedRef<boolean>;
119
+ items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
120
+ loadItems: (isSearch?: boolean) => Promise<void>;
121
+ handleSearch: (value: string) => Promise<void>;
123
122
  };
124
123
 
125
- declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, includedIds, params, }: {
126
- apiMethod: T;
127
- mapResultCallback: K;
128
- includedIds?: Parameters<T>[0]['includedIds'];
129
- params?: Parameters<T>[0];
130
- }): {
131
- search: vue.Ref<string>;
132
- options: vue.ComputedRef<ReturnType<K>[1][]>;
133
- loading: vue.Ref<boolean>;
134
- hasNextPage: vue.ComputedRef<boolean>;
135
- items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
136
- loadItems: (isSearch?: boolean) => Promise<void>;
137
- handleSearch: (value: string) => Promise<void>;
124
+ declare function useAsyncSelect<T extends (...args: any[]) => any, K extends (params: Awaited<ReturnType<T>>['results'][0]) => any>({ apiMethod, mapResultCallback, includedIds, params, }: {
125
+ apiMethod: T;
126
+ mapResultCallback: K;
127
+ includedIds?: Parameters<T>[0]['includedIds'];
128
+ params?: Parameters<T>[0];
129
+ }): {
130
+ search: vue.Ref<string>;
131
+ options: vue.ComputedRef<ReturnType<K>[1][]>;
132
+ loading: vue.Ref<boolean>;
133
+ hasNextPage: vue.ComputedRef<boolean>;
134
+ items: vue.Ref<Map<ReturnType<K>[0], ReturnType<K>[1]>>;
135
+ loadItems: (isSearch?: boolean) => Promise<void>;
136
+ handleSearch: (value: string) => Promise<void>;
138
137
  };
139
138
 
140
- declare const useClassName: (block: string) => {
141
- b: (blockSuffix?: string) => string;
142
- e: (element?: string) => string;
143
- m: (modifier?: string, condition?: boolean) => string;
144
- em: (element?: string, modifier?: string, condition?: boolean) => string;
145
- mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
146
- cssVar: (object: Record<string, string>) => Record<string, string>;
147
- cssVarName: (name: string) => string;
139
+ declare const useClassName: (block: string) => {
140
+ b: (blockSuffix?: string) => string;
141
+ e: (element?: string) => string;
142
+ m: (modifier?: string, condition?: boolean) => string;
143
+ em: (element?: string, modifier?: string, condition?: boolean) => string;
144
+ mv: (modifier: string, modifierValue: string, condition?: boolean) => string;
145
+ cssVar: (object: Record<string, string>) => Record<string, string>;
146
+ cssVarName: (name: string) => string;
148
147
  };
149
148
 
150
- /**
151
- * Обертка над dayjs, позволяющая задавать timezone
152
- * @see https://day.js.org/en/
153
- *
154
- * Использовать параметр timezone нужно крайне аккуратно,
155
- * может привести к утечкам памяти
156
- * @todo Подумать как сделать оптимальнее
157
- */
149
+ /**
150
+ * Обертка над dayjs, позволяющая задавать timezone
151
+ * @see https://day.js.org/en/
152
+ *
153
+ * Использовать параметр timezone нужно крайне аккуратно,
154
+ * может привести к утечкам памяти
155
+ * @todo Подумать как сделать оптимальнее
156
+ */
158
157
  declare function useDayjs(timezone?: string): (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean) => dayjs.Dayjs;
159
158
 
160
- interface BrowserInfo {
161
- isDeprecated?: boolean;
162
- name?: string;
163
- version?: string;
164
- os?: string;
165
- type?: string;
166
- options?: any;
167
- }
168
- type VersionsList = {
169
- [key in Browser]?: string | boolean;
170
- };
159
+ interface BrowserInfo {
160
+ isDeprecated?: boolean;
161
+ name?: string;
162
+ version?: string;
163
+ os?: string;
164
+ type?: string;
165
+ options?: any;
166
+ }
167
+ type VersionsList = {
168
+ [key in Browser]?: string | boolean;
169
+ };
171
170
  declare function useDetectBrowser(versions: VersionsList, userAgent?: any): BrowserInfo;
172
171
 
173
- /**
174
- * @see https://github.com/caiogondim/logdown.js#readme
175
- */
176
-
177
- interface Options {
178
- tag?: string;
179
- color?: string;
180
- debug?: boolean;
181
- }
172
+ /**
173
+ * @see https://github.com/caiogondim/logdown.js#readme
174
+ */
175
+
176
+ interface Options {
177
+ tag?: string;
178
+ color?: string;
179
+ debug?: boolean;
180
+ }
182
181
  declare function useLogger(scope: string, options?: Options): logdown.Logger;
183
182
 
184
183
  declare function validatePhone(rule: string, value: string): boolean;
185
184
 
186
- declare const isRequired: (value?: boolean, message?: string) => RuleItem;
187
- declare const isMax: (value?: number, message?: string) => {
188
- max: number;
189
- message: string;
190
- };
191
- declare const isMin: (value?: number, message?: string) => {
192
- min: number;
193
- message: string;
194
- };
195
- declare const isTypeEmail: (message?: string) => RuleItem;
196
- declare const isTypeUrl: (message?: string) => RuleItem;
197
- declare const isTypeNumber: (value?: number, message?: string) => RuleItem;
185
+ declare const isRequired: (value?: boolean, message?: string) => RuleItem;
186
+ declare const isMax: (value?: number, message?: string) => {
187
+ max: number;
188
+ message: string;
189
+ };
190
+ declare const isMin: (value?: number, message?: string) => {
191
+ min: number;
192
+ message: string;
193
+ };
194
+ declare const isTypeEmail: (message?: string) => RuleItem;
195
+ declare const isTypeUrl: (message?: string) => RuleItem;
196
+ declare const isTypeNumber: (value?: number, message?: string) => RuleItem;
198
197
  declare const isStrictLength: (value?: number, message?: string) => RuleItem;
199
198
 
200
199
  export { BrowserInfo, Dictionary, ResponseError, UiComponentsResolver, VersionsList, camelizeKeys, createClassName, formatMoney, genLoadingTableRows, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncMultiselect, useAsyncSelect, useClassName, useDayjs, useDetectBrowser, useLogger, validateNumber, validatePhone };
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import camelCase from 'lodash/camelCase.js';
2
+ import { CURRENCY_DEFAULT } from '@karta.io/common-data';
2
3
  import { parsePhoneNumberFromString } from 'libphonenumber-js';
3
4
  import snakeCase from 'lodash/snakeCase.js';
4
5
  import { ref, computed, onBeforeUnmount } from 'vue';
@@ -35,18 +36,18 @@ function createClassName(className) {
35
36
  }(className);
36
37
  }
37
38
 
38
- function formatMoney(value, currency, options = { locale: "en-US", minimumFractionDigits: 2, maximumFractionDigits: 2 }) {
39
+ function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
39
40
  let convertedValue = Number(value);
40
41
  if (value === null || Number.isNaN(convertedValue)) {
41
42
  return "";
42
43
  }
43
- const formatter = new Intl.NumberFormat(options.locale, {
44
- minimumFractionDigits: options.minimumFractionDigits,
45
- maximumFractionDigits: options.maximumFractionDigits,
46
- ...currency && {
47
- style: "currency",
48
- currency
49
- }
44
+ const { locale = "en-US", ...otherOptions } = options;
45
+ const formatter = new Intl.NumberFormat(locale, {
46
+ style: "currency",
47
+ currency,
48
+ minimumFractionDigits: 2,
49
+ maximumFractionDigits: 2,
50
+ ...otherOptions
50
51
  });
51
52
  return formatter.format(convertedValue);
52
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karta.io/utils",
3
- "version": "0.33.6",
3
+ "version": "0.33.8",
4
4
  "description": "karta.io utils for admin and application",
5
5
  "author": "Vitaly Blokhin <karambafe@gmail.com>",
6
6
  "homepage": "",
@@ -23,7 +23,7 @@
23
23
  "vue": "3.2.x"
24
24
  },
25
25
  "dependencies": {
26
- "@karta.io/common-data": "^0.33.6",
26
+ "@karta.io/common-data": "^0.33.8",
27
27
  "@vueuse/core": "9.13.0",
28
28
  "async-validator": "4.2.5",
29
29
  "dayjs": "1.11.7",