@thisisagile/easy-domain 15.29.3
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/README.md +282 -0
- package/dist/chunk-3N5M6QHW.mjs +132 -0
- package/dist/chunk-3N5M6QHW.mjs.map +1 -0
- package/dist/chunk-CKW4QYDN.mjs +16 -0
- package/dist/chunk-CKW4QYDN.mjs.map +1 -0
- package/dist/chunk-H2VHSGNX.mjs +35 -0
- package/dist/chunk-H2VHSGNX.mjs.map +1 -0
- package/dist/chunk-ODLLVCBP.mjs +6634 -0
- package/dist/chunk-ODLLVCBP.mjs.map +1 -0
- package/dist/chunk-RDITZTSA.mjs +41 -0
- package/dist/chunk-RDITZTSA.mjs.map +1 -0
- package/dist/chunk-SBXA2N6H.mjs +29 -0
- package/dist/chunk-SBXA2N6H.mjs.map +1 -0
- package/dist/chunk-VAHXDD2J.mjs +268 -0
- package/dist/chunk-VAHXDD2J.mjs.map +1 -0
- package/dist/chunk-XBORRJ6W.mjs +18 -0
- package/dist/chunk-XBORRJ6W.mjs.map +1 -0
- package/dist/enums/Country.d.ts +256 -0
- package/dist/enums/Country.mjs +8 -0
- package/dist/enums/Country.mjs.map +1 -0
- package/dist/enums/Currency.d.ts +124 -0
- package/dist/enums/Currency.mjs +8 -0
- package/dist/enums/Currency.mjs.map +1 -0
- package/dist/enums/Locale.d.ts +571 -0
- package/dist/enums/Locale.mjs +584 -0
- package/dist/enums/Locale.mjs.map +1 -0
- package/dist/enums/UnitOfMeasurement.d.ts +10 -0
- package/dist/enums/UnitOfMeasurement.mjs +8 -0
- package/dist/enums/UnitOfMeasurement.mjs.map +1 -0
- package/dist/enums/UnitOfWeight.d.ts +8 -0
- package/dist/enums/UnitOfWeight.mjs +8 -0
- package/dist/enums/UnitOfWeight.mjs.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +7997 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +18 -0
- package/dist/index.mjs.map +1 -0
- package/dist/structs/Address.d.ts +12 -0
- package/dist/structs/Address.mjs +47 -0
- package/dist/structs/Address.mjs.map +1 -0
- package/dist/structs/Box.d.ts +15 -0
- package/dist/structs/Box.mjs +44 -0
- package/dist/structs/Box.mjs.map +1 -0
- package/dist/structs/Dimension.d.ts +10 -0
- package/dist/structs/Dimension.mjs +9 -0
- package/dist/structs/Dimension.mjs.map +1 -0
- package/dist/structs/Money.d.ts +14 -0
- package/dist/structs/Money.mjs +48 -0
- package/dist/structs/Money.mjs.map +1 -0
- package/dist/structs/Name.d.ts +8 -0
- package/dist/structs/Name.mjs +26 -0
- package/dist/structs/Name.mjs.map +1 -0
- package/dist/structs/Weight.d.ts +13 -0
- package/dist/structs/Weight.mjs +43 -0
- package/dist/structs/Weight.mjs.map +1 -0
- package/dist/values/EAN.d.ts +5 -0
- package/dist/values/EAN.mjs +23 -0
- package/dist/values/EAN.mjs.map +1 -0
- package/dist/values/Email.d.ts +8 -0
- package/dist/values/Email.mjs +29 -0
- package/dist/values/Email.mjs.map +1 -0
- package/dist/values/IBAN.d.ts +5 -0
- package/dist/values/IBAN.mjs +23 -0
- package/dist/values/IBAN.mjs.map +1 -0
- package/dist/values/PostalCode.d.ts +8 -0
- package/dist/values/PostalCode.mjs +12 -0
- package/dist/values/PostalCode.mjs.map +1 -0
- package/dist/values/Slug.d.ts +6 -0
- package/dist/values/Slug.mjs +24 -0
- package/dist/values/Slug.mjs.map +1 -0
- package/dist/values/Url.d.ts +22 -0
- package/dist/values/Url.mjs +29 -0
- package/dist/values/Url.mjs.map +1 -0
- package/package.json +44 -0
- package/src/enums/Country.ts +269 -0
- package/src/enums/Currency.ts +131 -0
- package/src/enums/Locale.ts +584 -0
- package/src/enums/UnitOfMeasurement.ts +17 -0
- package/src/enums/UnitOfWeight.ts +15 -0
- package/src/enums/countries.json +251 -0
- package/src/enums/currencies.json +1073 -0
- package/src/enums/locales.json +565 -0
- package/src/index.ts +19 -0
- package/src/structs/Address.ts +23 -0
- package/src/structs/Box.ts +28 -0
- package/src/structs/Dimension.ts +24 -0
- package/src/structs/Money.ts +37 -0
- package/src/structs/Name.ts +13 -0
- package/src/structs/Weight.ts +34 -0
- package/src/values/EAN.ts +12 -0
- package/src/values/Email.ts +20 -0
- package/src/values/IBAN.ts +12 -0
- package/src/values/PostalCode.ts +17 -0
- package/src/values/Slug.ts +14 -0
- package/src/values/Url.ts +73 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Struct, isEmpty, text, required } from '@thisisagile/easy';
|
|
2
|
+
import { Currency } from '../enums/Currency';
|
|
3
|
+
|
|
4
|
+
export class Money extends Struct {
|
|
5
|
+
@required() readonly currency = Currency.byId<Currency>(this.state.currency);
|
|
6
|
+
@required() readonly value = this.state.value as number;
|
|
7
|
+
|
|
8
|
+
add(amount: number): Money {
|
|
9
|
+
return money(this.currency, this.value + amount);
|
|
10
|
+
}
|
|
11
|
+
subtract(amount: number): Money {
|
|
12
|
+
return money(this.currency, this.value - amount);
|
|
13
|
+
}
|
|
14
|
+
times(n: number): Money {
|
|
15
|
+
return money(this.currency, this.value * n);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
toString(): string {
|
|
19
|
+
return text(this.currency?.code)
|
|
20
|
+
.with(' ', this.value?.toFixed(this.currency?.digits ?? 2))
|
|
21
|
+
.toString();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static zero(currency: Currency): Money {
|
|
25
|
+
return Money.amount(currency);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static amount(currency: Currency, value: number = 0): Money {
|
|
29
|
+
return money(currency, value);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const money = (currency: Currency, value: number): Money => new Money({ currency: currency.id, value });
|
|
34
|
+
|
|
35
|
+
export const isMoney = (m?: unknown): m is Money => {
|
|
36
|
+
return !isEmpty(m) && m instanceof Money;
|
|
37
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Struct, Json, text, required } from '@thisisagile/easy';
|
|
2
|
+
|
|
3
|
+
export class Name extends Struct {
|
|
4
|
+
@required() readonly first: string = this.state.first;
|
|
5
|
+
readonly middle: string = this.state.middle;
|
|
6
|
+
@required() readonly last: string = this.state.last;
|
|
7
|
+
|
|
8
|
+
toString(): string {
|
|
9
|
+
return text(this.first, '').add(this.middle, ' ').add(this.last, ' ').toString();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const name = (n?: Json): Name => new Name(n);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { UnitOfWeight } from '../enums/UnitOfWeight';
|
|
2
|
+
import { Struct, required } from '@thisisagile/easy';
|
|
3
|
+
|
|
4
|
+
export class Weight extends Struct {
|
|
5
|
+
@required() readonly value = this.state.value as number;
|
|
6
|
+
readonly uow = UnitOfWeight.byId<UnitOfWeight>(this.state.uow, UnitOfWeight.G);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
@deprecated use inGrams getter instead
|
|
10
|
+
*/
|
|
11
|
+
sizeInG(): number {
|
|
12
|
+
return this.inGrams;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get inGrams(): number {
|
|
16
|
+
return this.value * this.uow.gMultiplier;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
gte(w: Weight): boolean {
|
|
20
|
+
return this.inGrams >= w.inGrams;
|
|
21
|
+
}
|
|
22
|
+
lte(w: Weight): boolean {
|
|
23
|
+
return this.inGrams <= w.inGrams;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
between(lower: Weight, upper = weight(Number.MAX_VALUE, this.uow)) {
|
|
27
|
+
return this.gte(lower) && this.lte(upper);
|
|
28
|
+
}
|
|
29
|
+
sum(add: Weight): Weight {
|
|
30
|
+
return weight((this.inGrams + add.inGrams) / this.uow.gMultiplier, this.uow);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const weight = (value: number, uow?: UnitOfWeight): Weight => new Weight({ value, uow });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isEAN as validateEAN } from 'validator';
|
|
2
|
+
import { asString, isEmpty, Value } from '@thisisagile/easy';
|
|
3
|
+
|
|
4
|
+
export class EAN extends Value {
|
|
5
|
+
get isValid(): boolean {
|
|
6
|
+
return isEAN(this.value);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const isEAN = (ean?: unknown): boolean => {
|
|
11
|
+
return !isEmpty(ean) && validateEAN(asString(ean));
|
|
12
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isEmail as validateEmail } from 'validator';
|
|
2
|
+
import { asString, isEmpty, text, Value } from '@thisisagile/easy';
|
|
3
|
+
|
|
4
|
+
export class Email extends Value {
|
|
5
|
+
constructor(email?: unknown) {
|
|
6
|
+
super(asString(email).trim().toLowerCase());
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get isValid(): boolean {
|
|
10
|
+
return isEmail(this.value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get name(): string {
|
|
14
|
+
return text(this.value.split('@')[0]).replace('.', ' ').title.toString();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const email = (email?: unknown): Email => new Email(email);
|
|
19
|
+
|
|
20
|
+
export const isEmail = (e?: unknown): boolean => !isEmpty(e) && validateEmail(asString(e));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isIBAN as validateIBAN } from 'validator';
|
|
2
|
+
import { asString, isEmpty, Value } from '@thisisagile/easy';
|
|
3
|
+
|
|
4
|
+
export class IBAN extends Value {
|
|
5
|
+
get isValid(): boolean {
|
|
6
|
+
return isIBAN(this.value);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const isIBAN = (iban?: unknown): boolean => {
|
|
11
|
+
return !isEmpty(iban) && validateIBAN(asString(iban));
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Id, text, Value } from '@thisisagile/easy';
|
|
2
|
+
import { Country } from '../enums/Country';
|
|
3
|
+
import { isPostalCode, PostalCodeLocale } from 'validator';
|
|
4
|
+
|
|
5
|
+
export class PostalCode extends Value {
|
|
6
|
+
constructor(
|
|
7
|
+
postalCode?: unknown,
|
|
8
|
+
readonly country: Country | Id = Country.NL
|
|
9
|
+
) {
|
|
10
|
+
super(text(postalCode).replace(' ', '').toString());
|
|
11
|
+
}
|
|
12
|
+
get isValid(): boolean {
|
|
13
|
+
return isPostalCode(this.value, (this.country instanceof Country ? this.country.id : text(this.country).upper) as PostalCodeLocale);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const postalCode = (postalCode?: unknown, country: Country | Id = Country.NL) => new PostalCode(postalCode, country);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isNotEmpty, text, Value } from '@thisisagile/easy';
|
|
2
|
+
import { isSlug } from 'validator';
|
|
3
|
+
|
|
4
|
+
export class Slug extends Value {
|
|
5
|
+
constructor(slug?: unknown) {
|
|
6
|
+
super(text(slug).slug.toString());
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get isValid(): boolean {
|
|
10
|
+
return isNotEmpty(this.value) && isSlug(this.value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const toSlug = (slug?: unknown): Slug => new Slug(slug);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isURL as validateUrl } from 'validator';
|
|
2
|
+
import { asString, isEmpty, Value } from '@thisisagile/easy';
|
|
3
|
+
|
|
4
|
+
export interface UrlOptions {
|
|
5
|
+
/**
|
|
6
|
+
* @default ['http','https','ftp']
|
|
7
|
+
*/
|
|
8
|
+
protocols?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
require_tld?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
require_protocol?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
require_host?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* if set as true isURL will check if port is present in the URL
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
require_port?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
require_valid_protocol?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
allow_underscores?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
host_whitelist?: Array<string | RegExp>;
|
|
38
|
+
/**
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
host_blacklist?: Array<string | RegExp>;
|
|
42
|
+
/**
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
allow_trailing_dot?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
allow_protocol_relative_urls?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
disallow_auth?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class Url extends Value {
|
|
57
|
+
constructor(
|
|
58
|
+
value: unknown,
|
|
59
|
+
readonly options?: UrlOptions
|
|
60
|
+
) {
|
|
61
|
+
super(asString(value));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get isValid(): boolean {
|
|
65
|
+
return isUrl(this.value, this.options);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const url = (url: unknown, options?: UrlOptions): Url => new Url(url, options);
|
|
70
|
+
|
|
71
|
+
export const isUrl = (url?: unknown, options?: UrlOptions): boolean => {
|
|
72
|
+
return !isEmpty(url) && validateUrl(asString(url), options);
|
|
73
|
+
};
|