@stndrds/constants 0.1.0-alpha.14

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 ADDED
@@ -0,0 +1,210 @@
1
+ # @stndrds/constants
2
+
3
+ Standard constants library for And You Create applications.
4
+
5
+ Provides type-safe constants for:
6
+ - 🌍 Countries (ISO codes, phone codes)
7
+ - 💰 Currencies (codes, symbols, decimals)
8
+ - 🎨 Colors
9
+ - 🔤 Icons
10
+ - 📁 File sizes
11
+ - 📄 MIME types
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add @stndrds/constants
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Countries
22
+
23
+ ```typescript
24
+ import { COUNTRIES, getCountryByIso2, isValidIso2 } from "@stndrds/constants";
25
+
26
+ // Get country by ISO2 code
27
+ const france = COUNTRIES.FR;
28
+ console.log(france.name); // "France"
29
+ console.log(france.phoneCode); // "+33"
30
+
31
+ // Lookup functions
32
+ const country = getCountryByIso2("FR");
33
+ const isValid = isValidIso2("FR"); // true
34
+
35
+ // Type-safe ISO codes
36
+ import type { CountryIso2, CountryIso3 } from "@stndrds/constants";
37
+ const code: CountryIso2 = "FR"; // Type-safe
38
+ ```
39
+
40
+ ### Currencies
41
+
42
+ ```typescript
43
+ import { CURRENCIES, getCurrency, getCurrencySymbol } from "@stndrds/constants";
44
+
45
+ // Get currency
46
+ const euro = CURRENCIES.EUR;
47
+ console.log(euro.name); // "Euro"
48
+ console.log(euro.symbol); // "€"
49
+ console.log(euro.decimals); // 2
50
+
51
+ // Helper functions
52
+ const symbol = getCurrencySymbol("EUR"); // "€"
53
+ const currency = getCurrency("USD");
54
+
55
+ // Type-safe currency codes
56
+ import type { CurrencyCode } from "@stndrds/constants";
57
+ const code: CurrencyCode = "EUR"; // Type-safe
58
+ ```
59
+
60
+ ### File Sizes
61
+
62
+ ```typescript
63
+ import { FILE_SIZE, RECOMMENDED_MAX_SIZES, formatBytes, mbToBytes } from "@stndrds/constants";
64
+
65
+ // Intuitive constants
66
+ const avatarMaxSize = FILE_SIZE.MB_2; // 2,097,152 bytes
67
+ const documentMaxSize = FILE_SIZE.MB_10; // 10,485,760 bytes
68
+ const videoMaxSize = FILE_SIZE.MB_500; // 524,288,000 bytes
69
+
70
+ // Recommended sizes by use case
71
+ const maxSize = RECOMMENDED_MAX_SIZES.AVATAR; // 2 MB
72
+ const maxSize = RECOMMENDED_MAX_SIZES.DOCUMENT; // 10 MB
73
+ const maxSize = RECOMMENDED_MAX_SIZES.VIDEO; // 500 MB
74
+
75
+ // Conversion utilities
76
+ const bytes = mbToBytes(5); // 5,242,880
77
+ const formatted = formatBytes(1048576); // "1 MB"
78
+
79
+ // Validation
80
+ import { isWithinSizeLimit } from "@stndrds/constants";
81
+ const isValid = isWithinSizeLimit(1048576, FILE_SIZE.MB_5); // true
82
+ ```
83
+
84
+ ### MIME Types
85
+
86
+ ```typescript
87
+ import {
88
+ IMAGE_MIME_TYPES,
89
+ DOCUMENT_MIME_TYPES,
90
+ VIDEO_MIME_TYPES,
91
+ WEB_IMAGES,
92
+ OFFICE_DOCUMENTS,
93
+ isImageMimeType,
94
+ getExtensionFromMimeType,
95
+ } from "@stndrds/constants";
96
+
97
+ // Individual MIME types
98
+ const jpeg = IMAGE_MIME_TYPES.JPEG; // "image/jpeg"
99
+ const pdf = DOCUMENT_MIME_TYPES.PDF; // "application/pdf"
100
+ const mp4 = VIDEO_MIME_TYPES.MP4; // "video/mp4"
101
+
102
+ // Grouped collections
103
+ const webImages = WEB_IMAGES; // ["image/jpeg", "image/png", "image/gif", "image/webp"]
104
+ const officeFiles = OFFICE_DOCUMENTS; // [PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX]
105
+
106
+ // Type checking
107
+ const isImage = isImageMimeType("image/jpeg"); // true
108
+ const isDoc = isDocumentMimeType("application/pdf"); // true
109
+
110
+ // Get extension
111
+ const ext = getExtensionFromMimeType("image/jpeg"); // "jpg"
112
+
113
+ // Type-safe MIME types
114
+ import type { MimeType, ImageMimeType } from "@stndrds/constants";
115
+ const type: MimeType = "image/jpeg"; // Type-safe
116
+ ```
117
+
118
+ ### Integration with @stndrds/schema
119
+
120
+ ```typescript
121
+ import { file, location, currency, phone } from "@stndrds/schema";
122
+ import {
123
+ FILE_SIZE,
124
+ WEB_IMAGES,
125
+ DOCUMENT_MIME_TYPES,
126
+ RECOMMENDED_MAX_SIZES,
127
+ } from "@stndrds/constants";
128
+
129
+ // File attribute with MIME type validation
130
+ const avatar = file({ id: "avatar", name: "avatar", label: "Avatar" })
131
+ .maxSize(RECOMMENDED_MAX_SIZES.AVATAR)
132
+ .allowedTypes(WEB_IMAGES)
133
+ .build();
134
+
135
+ // Document upload
136
+ const document = file({ id: "doc", name: "document", label: "Document" })
137
+ .maxSize(FILE_SIZE.MB_10)
138
+ .allowedTypes([DOCUMENT_MIME_TYPES.PDF, DOCUMENT_MIME_TYPES.DOCX])
139
+ .build();
140
+
141
+ // Location with country restriction
142
+ const address = location({ id: "addr", name: "address", label: "Address" })
143
+ .granularity("full")
144
+ .defaultCountry("FRA")
145
+ .allowedCountries(["FRA", "DEU", "GBR"])
146
+ .build();
147
+
148
+ // Currency with restrictions
149
+ const price = currency({ id: "price", name: "price", label: "Price" })
150
+ .defaultCurrency("EUR")
151
+ .allowedCurrencies(["EUR", "USD", "GBP"])
152
+ .build();
153
+
154
+ // Phone with default country
155
+ const mobile = phone({ id: "phone", name: "phone", label: "Phone" })
156
+ .defaultCountry("FRA")
157
+ .build();
158
+ ```
159
+
160
+ ## Available Constants
161
+
162
+ ### Countries
163
+ 60+ countries with ISO2, ISO3, numeric codes, and phone codes
164
+
165
+ ### Currencies
166
+ 50+ currencies with codes, symbols, and decimal precision
167
+
168
+ ### File Sizes
169
+ - Bytes: B_1, B_10, B_100, B_512
170
+ - Kilobytes: KB_1, KB_2, KB_5, KB_10, KB_50, KB_100, KB_500
171
+ - Megabytes: MB_1, MB_2, MB_5, MB_10, MB_20, MB_25, MB_50, MB_100, MB_200, MB_500
172
+ - Gigabytes: GB_1, GB_2, GB_5, GB_10
173
+
174
+ ### MIME Types
175
+ - Images: JPEG, PNG, GIF, WebP, SVG, BMP, TIFF, HEIC, HEIF
176
+ - Documents: PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX, ODT, TXT, CSV, Markdown
177
+ - Archives: ZIP, RAR, TAR, GZIP, 7Z, BZ2
178
+ - Audio: MP3, WAV, OGG, AAC, FLAC, M4A
179
+ - Video: MP4, WebM, OGG, AVI, MOV, MKV
180
+ - Code: JavaScript, TypeScript, JSON, XML, HTML, CSS, Python, Java
181
+ - Fonts: TTF, OTF, WOFF, WOFF2
182
+
183
+ ## Testing
184
+
185
+ ```bash
186
+ # Run tests
187
+ pnpm test
188
+
189
+ # Run tests with coverage
190
+ pnpm test:coverage
191
+ ```
192
+
193
+ ## Types
194
+
195
+ All exports are fully typed with TypeScript.
196
+
197
+ ```typescript
198
+ import type {
199
+ CountryIso2,
200
+ CountryIso3,
201
+ CurrencyCode,
202
+ MimeType,
203
+ ImageMimeType,
204
+ DocumentMimeType,
205
+ } from "@stndrds/constants";
206
+ ```
207
+
208
+ ## License
209
+
210
+ MIT