@bolttech/form-engine-core 1.1.0-beta.0 → 1.1.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/CHANGELOG.md +36 -0
- package/credit-card.d.ts +743 -0
- package/credit-card.esm.js +1 -0
- package/currency.d.ts +131 -0
- package/currency.esm.js +1 -0
- package/date.d.ts +582 -0
- package/date.esm.js +1 -0
- package/document.d.ts +527 -0
- package/document.esm.js +1 -0
- package/index.d.ts +2393 -0
- package/index.esm.js +1 -4435
- package/lite.d.ts +2393 -0
- package/lite.esm.js +1 -0
- package/package.json +50 -10
- package/src/constants/constants.d.ts +2 -1
- package/src/helpers/SafeSubject.d.ts +12 -2
- package/src/helpers/helpers.d.ts +6 -6
- package/src/helpers/lodash-replacements.d.ts +41 -0
- package/src/helpers/validation.d.ts +2 -1
- package/src/index.d.ts +5 -0
- package/src/interfaces/schema.d.ts +28 -1
- package/src/lite.d.ts +30 -0
- package/src/managers/field.d.ts +20 -3
- package/src/managers/form.d.ts +8 -2
- package/src/masks/currency.d.ts +29 -0
- package/src/masks/handler.d.ts +1 -1
- package/src/masks/string.d.ts +0 -62
- package/src/plugins/credit-card.d.ts +4 -0
- package/src/plugins/currency.d.ts +2 -0
- package/src/plugins/date.d.ts +2 -0
- package/src/plugins/document.d.ts +2 -0
- package/src/registry.d.ts +20 -0
- package/src/types/schema.d.ts +42 -23
- package/src/types/utility.d.ts +7 -4
- package/src/validations/custom.d.ts +3 -1
- package/index.esm.d.ts +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"credit-card-type";const r={},t={},i=(r,t)=>{const i=n(null==r?void 0:r.toString()),d=e(i);return["object"==typeof t&&t.length?null==d?void 0:d.filter(({type:e})=>t.some(r=>r===e))[0]:d[0],i]},n=e=>null==e?void 0:e.replace(/ /g,""),d=(e,r=4,t="/")=>{const i=e.replace(/\D/g,""),n=i.slice(0,2);return i.length>=5?`${n}${t}${i.slice(2,r)}`:i.length>=3?`${n}${t}${i.slice(2)}`:i},s=(e,r)=>{if(!e)return!0;const[t]=i(String(e),r.isCreditCard);return!t},l=(e,r)=>{var t;if(!e||!r.isCreditCodeMatch)return!1;const[n]=i(r.isCreditCodeMatch.numberCard,r.isCreditCodeMatch.availableOptions);return(null===(t=null==n?void 0:n.code)||void 0===t?void 0:t.size)!==e.length},o=(e,r)=>{if(!e||!r.isCreditCardAndLength)return!1;const[t,n]=i(e,r.isCreditCardAndLength);return t&&!t.lengths.includes(n.length)},c=(e,r)=>{if(!r.gapsCreditCard)return e;const[t,n]=i(e,null==r?void 0:r.gapsCreditCard);return((e,r)=>r?((e,r=[])=>{const[t,i]=r.reduce(([e,t],i,n)=>[`${e}([0-9]{0,${i-(r[n-1]||0)}})`,`${t}$${n+1} `],["",""]);return e.replace(new RegExp(t),i).trim()})(e.slice(0,null==r?void 0:r.lengths[0]),r.gaps):null==e?void 0:e.slice(0,19))(n,t)},a=e=>((e,r)=>{if(!(null==r?void 0:r.generic))return e;let t=e;return r.generic.forEach(r=>{const{to:i=t.length,mask:n}=r;let{from:d}=r;if(i>e.length-1)return;0===d&&(d=1);const s=new Array(i-d+2).join(n);t=t.slice(0,d-1)+s+t.slice(i)}),t})(e,{generic:[{from:1,to:4,mask:"x"},{from:6,to:9,mask:"x"},{from:11,to:14,mask:"x"},{from:16,to:19,mask:"x"}]}),g=e=>e.replace(/[^\dA-Z]/g,"").replace(/(.{4})/g,"$1 ").trim(),u=e=>d(e),C=e=>d(e,9,"-");Object.assign({},{isCreditCard:s,isCreditCodeMatch:l,isCreditCardAndLength:o}),Object.assign(r,{gapsCreditCard:c}),Object.assign(t,{secureCreditCard:a,card:g,cardDate:u,fein:C});export{g as card,u as cardDate,C as fein,c as gapsCreditCard,s as isCreditCard,o as isCreditCardAndLength,l as isCreditCodeMatch,a as secureCreditCard};
|
package/currency.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { TCurrencyCode } from '@gaignoux/currency';
|
|
2
|
+
|
|
3
|
+
/** @virtual */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Mask types
|
|
7
|
+
* @type TCurrencyMask
|
|
8
|
+
* Represents the mask configuration for currency values.
|
|
9
|
+
*
|
|
10
|
+
* @property {'left' | 'right'} [align] - The alignment of the currency symbol. (default: right)
|
|
11
|
+
* @property {string} [decimal] - The decimal separator. (default: '.')
|
|
12
|
+
* @property {number} [precision] - The number of decimal places. (default: 2)
|
|
13
|
+
* @property {TCurrencyCode} [prefix] - The currency symbol prefix. (default: '$')
|
|
14
|
+
* @property {string} [thousands] - The thousands separator. (default: ',')
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const currencyMask: TCurrencyMask = {
|
|
19
|
+
* align: 'left',
|
|
20
|
+
* decimal: '.',
|
|
21
|
+
* precision: 2,
|
|
22
|
+
* prefix: '$',
|
|
23
|
+
* thousands: ','
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
type TCurrencyMask = {
|
|
28
|
+
align?: 'left' | 'right';
|
|
29
|
+
decimal?: string;
|
|
30
|
+
precision?: number;
|
|
31
|
+
prefix?: TCurrencyCode;
|
|
32
|
+
thousands?: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* @type TMaskGeneric
|
|
36
|
+
* Represents a generic mask configuration.
|
|
37
|
+
*
|
|
38
|
+
* @property {number} to - The ending position of the mask.
|
|
39
|
+
* @property {number} from - The starting position of the mask.
|
|
40
|
+
* @property {string} mask - The mask pattern to apply.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const maskGeneric: TMaskGeneric = { to: 4, from: 0, mask: '****' };
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
type TMaskGeneric = {
|
|
48
|
+
to: number;
|
|
49
|
+
from: number;
|
|
50
|
+
mask: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* @type TMasks
|
|
54
|
+
* Represents the different types of masks that can be applied to form field values.
|
|
55
|
+
*
|
|
56
|
+
* @property {TCurrencyMask} [currency] - Mask for currency values.
|
|
57
|
+
* @property {TMaskGeneric[]} [generic] - Array of generic masks.
|
|
58
|
+
* @property {string} [custom] - Custom mask pattern.
|
|
59
|
+
* @property {boolean} [secureCreditCard] - Mask for securing credit card values.
|
|
60
|
+
* @property {boolean} [card] - Mask for card values.
|
|
61
|
+
* @property {boolean} [cardDate] - Mask for card date values.
|
|
62
|
+
* @property {boolean} [fein] - Mask for FEIN (Federal Employer Identification Number).
|
|
63
|
+
* @property {string | number} [replaceAll] - Value to replace all matches.
|
|
64
|
+
* @property {(value: unknown) => string} [callback] - Custom mask callback function.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const masks: TMasks = {
|
|
69
|
+
* currency: { align: 'left', decimal: '.', precision: 2, prefix: '$', thousands: ',' },
|
|
70
|
+
* generic: [{ to: 4, from: 0, mask: '****' }],
|
|
71
|
+
* custom: '###-##-####',
|
|
72
|
+
* secureCreditCard: true,
|
|
73
|
+
* card: true,
|
|
74
|
+
* cardDate: true,
|
|
75
|
+
* fein: true,
|
|
76
|
+
* replaceAll: '*',
|
|
77
|
+
* callback: (value) => value.toString().replace(/\d/g, '*')
|
|
78
|
+
* };
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
type TMasks = {
|
|
82
|
+
/** Mask for currency values. */
|
|
83
|
+
currency?: TCurrencyMask;
|
|
84
|
+
/** Array of generic masks. */
|
|
85
|
+
generic?: TMaskGeneric[];
|
|
86
|
+
/** Custom mask pattern. */
|
|
87
|
+
custom?: string | null;
|
|
88
|
+
/** Mask for securing credit card values. */
|
|
89
|
+
secureCreditCard?: boolean;
|
|
90
|
+
/** Mask for card values. */
|
|
91
|
+
card?: boolean;
|
|
92
|
+
/** Mask for card date values. */
|
|
93
|
+
cardDate?: boolean;
|
|
94
|
+
/** Mask for FEIN (Federal Employer Identification Number). */
|
|
95
|
+
fein?: boolean;
|
|
96
|
+
/** Value to replace all matches. */
|
|
97
|
+
replaceAll?: string | number;
|
|
98
|
+
/** Custom mask callback function. */
|
|
99
|
+
callback?: (value: unknown) => string;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Formats a numeric value as a currency string based on the provided mask configuration.
|
|
104
|
+
*
|
|
105
|
+
* @param value - The numeric value to be formatted.
|
|
106
|
+
* @param masks - An object containing the mask configuration.
|
|
107
|
+
* @returns The formatted currency string.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* import { currency } from './path/to/maskFunctions';
|
|
112
|
+
*
|
|
113
|
+
* const masks = {
|
|
114
|
+
* currency: {
|
|
115
|
+
* align: 'right',
|
|
116
|
+
* decimal: ',',
|
|
117
|
+
* precision: 2,
|
|
118
|
+
* prefix: 'USD',
|
|
119
|
+
* thousands: '.'
|
|
120
|
+
* }
|
|
121
|
+
* };
|
|
122
|
+
*
|
|
123
|
+
* const formattedValue = currency(12345.67, masks);
|
|
124
|
+
* console.log(formattedValue); // Output: '12.345,67 $'
|
|
125
|
+
*
|
|
126
|
+
* PS: To unCurrency this value, usage onlyFloatNumber formatter
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare const currency: (value: string | number, masks: TMasks) => unknown;
|
|
130
|
+
|
|
131
|
+
export { currency };
|
package/currency.esm.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getCurrencySymbol as e}from"@gaignoux/currency";const r=(r,t)=>{if(!(null==t?void 0:t.currency))return r;const{align:n="",decimal:c=".",precision:i=2,prefix:l="BBD",thousands:o=","}=t.currency;let u=(function(e){return"number"==typeof e||"object"==typeof e&&null!==e&&"[object Number]"===Object.prototype.toString.call(e)}(r)?Number(r).toFixed(i):r).replace(/[^0-9]/g,"");if(!u)return"";let g=u.slice(0,u.length-i).replace(/^0*/g,"").replace(/\B(?=(\d{3})+(?!\d))/g,o);""===g&&(g="0"),"right"===n&&String(r).endsWith(" ")&&(u=u.slice(0,-1));let p=g,s=u.slice(u.length-i);if(i>0&&(s="0".repeat(i-s.length)+s,p+=c+s),!n)return p;const a=e(l);return"left"===n?`${a} ${p}`:`${p} ${a}`};Object.assign({},{currency:r});export{r as currency};
|