@standards/constants 1.0.0-alpha.415 → 1.0.0-alpha.418

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 CHANGED
@@ -21,7 +21,7 @@ pnpm add @standards/constants
21
21
  ### Countries
22
22
 
23
23
  ```typescript
24
- import { COUNTRIES, getCountryByIso2, isValidIso2 } from "@standards/constants";
24
+ import { COUNTRIES, getCountryByIso2 } from "@standards/constants";
25
25
 
26
26
  // Get country by ISO2 code
27
27
  const france = COUNTRIES.FR;
@@ -30,7 +30,6 @@ console.log(france.phoneCode); // "+33"
30
30
 
31
31
  // Lookup functions
32
32
  const country = getCountryByIso2("FR");
33
- const isValid = isValidIso2("FR"); // true
34
33
 
35
34
  // Type-safe ISO codes
36
35
  import type { CountryIso2, CountryIso3 } from "@standards/constants";
@@ -40,7 +39,7 @@ const code: CountryIso2 = "FR"; // Type-safe
40
39
  ### Currencies
41
40
 
42
41
  ```typescript
43
- import { CURRENCIES, getCurrency, getCurrencySymbol } from "@standards/constants";
42
+ import { CURRENCIES, isValidCurrencyCode } from "@standards/constants";
44
43
 
45
44
  // Get currency
46
45
  const euro = CURRENCIES.EUR;
@@ -48,9 +47,8 @@ console.log(euro.name); // "Euro"
48
47
  console.log(euro.symbol); // "€"
49
48
  console.log(euro.decimals); // 2
50
49
 
51
- // Helper functions
52
- const symbol = getCurrencySymbol("EUR"); // "€"
53
- const currency = getCurrency("USD");
50
+ // Type guard
51
+ const isValid = isValidCurrencyCode("usd"); // true
54
52
 
55
53
  // Type-safe currency codes
56
54
  import type { CurrencyCode } from "@standards/constants";
@@ -60,71 +58,36 @@ const code: CurrencyCode = "EUR"; // Type-safe
60
58
  ### File Sizes
61
59
 
62
60
  ```typescript
63
- import { FILE_SIZE, RECOMMENDED_MAX_SIZES, mbToBytes } from "@standards/constants";
61
+ import { FILE_SIZE } from "@standards/constants";
64
62
 
65
63
  // Intuitive constants
66
64
  const avatarMaxSize = FILE_SIZE.MB_2; // 2,097,152 bytes
67
65
  const documentMaxSize = FILE_SIZE.MB_10; // 10,485,760 bytes
68
66
  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
-
78
- // Validation
79
- import { isWithinSizeLimit } from "@standards/constants";
80
- const isValid = isWithinSizeLimit(1048576, FILE_SIZE.MB_5); // true
81
67
  ```
82
68
 
83
69
  ### MIME Types
84
70
 
85
71
  ```typescript
86
- import {
87
- IMAGE_MIME_TYPES,
88
- DOCUMENT_MIME_TYPES,
89
- VIDEO_MIME_TYPES,
90
- WEB_IMAGES,
91
- OFFICE_DOCUMENTS,
92
- isImageMimeType,
93
- } from "@standards/constants";
72
+ import { DOCUMENT_MIME_TYPES, IMAGE_MIME_TYPES, INLINE_IMAGE_ACCEPT } from "@standards/constants";
94
73
 
95
- // Individual MIME types
96
74
  const jpeg = IMAGE_MIME_TYPES.JPEG; // "image/jpeg"
97
75
  const pdf = DOCUMENT_MIME_TYPES.PDF; // "application/pdf"
98
- const mp4 = VIDEO_MIME_TYPES.MP4; // "video/mp4"
99
76
 
100
- // Grouped collections
101
- const webImages = WEB_IMAGES; // ["image/jpeg", "image/png", "image/gif", "image/webp"]
102
- const officeFiles = OFFICE_DOCUMENTS; // [PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX]
103
-
104
- // Type checking
105
- const isImage = isImageMimeType("image/jpeg"); // true
106
- const isDoc = isDocumentMimeType("application/pdf"); // true
107
-
108
- // Type-safe MIME types
109
- import type { MimeType, ImageMimeType } from "@standards/constants";
110
- const type: MimeType = "image/jpeg"; // Type-safe
77
+ // The raster images a browser may paint inline, as a file input's `accept`
78
+ const accept = INLINE_IMAGE_ACCEPT; // "image/png,image/jpeg,image/gif,image/webp,image/avif"
111
79
  ```
112
80
 
113
81
  ### Integration with @standards/schema
114
82
 
115
83
  ```typescript
116
84
  import { currency, document, location, phone } from "@standards/schema";
117
- import {
118
- FILE_SIZE,
119
- WEB_IMAGES,
120
- DOCUMENT_MIME_TYPES,
121
- RECOMMENDED_MAX_SIZES,
122
- } from "@standards/constants";
85
+ import { DOCUMENT_MIME_TYPES, FILE_SIZE, IMAGE_MIME_TYPES } from "@standards/constants";
123
86
 
124
87
  // File attribute with MIME type validation
125
88
  const avatar = document("avatar", "Avatar")
126
- .maxFileSize(RECOMMENDED_MAX_SIZES.AVATAR)
127
- .accepts([...WEB_IMAGES])
89
+ .maxFileSize(FILE_SIZE.MB_2)
90
+ .accepts([IMAGE_MIME_TYPES.JPEG, IMAGE_MIME_TYPES.PNG, IMAGE_MIME_TYPES.WEBP])
128
91
  .build();
129
92
 
130
93
  // Document upload
@@ -167,13 +130,11 @@ const mobile = phone("phone", "Phone")
167
130
  - Gigabytes: GB_1, GB_2, GB_5, GB_10
168
131
 
169
132
  ### MIME Types
170
- - Images: JPEG, PNG, GIF, WebP, SVG, BMP, TIFF, HEIC, HEIF
171
- - Documents: PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX, ODT, TXT, CSV, Markdown
172
- - Archives: ZIP, RAR, TAR, GZIP, 7Z, BZ2
173
- - Audio: MP3, WAV, OGG, AAC, FLAC, M4A
174
- - Video: MP4, WebM, OGG, AVI, MOV, MKV
175
- - Code: JavaScript, TypeScript, JSON, XML, HTML, CSS, Python, Java
176
- - Fonts: TTF, OTF, WOFF, WOFF2
133
+ - Images (`IMAGE_MIME_TYPES`): JPEG, PNG, GIF, WebP, SVG, BMP, TIFF, HEIC, HEIF
134
+ - Documents (`DOCUMENT_MIME_TYPES`): PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX, ODT, TXT, CSV, Markdown
135
+ - Audio (`AUDIO_MIME_TYPES`): MP3, WAV, OGG, AAC, FLAC, M4A
136
+ - Code (`CODE_MIME_TYPES`): JavaScript, TypeScript, JSON, XML, HTML, CSS, Python, Java
137
+ - Email (`EMAIL_MIME_TYPES`): EML, Outlook MSG
177
138
 
178
139
  ## Testing
179
140
 
@@ -194,9 +155,6 @@ import type {
194
155
  CountryIso2,
195
156
  CountryIso3,
196
157
  CurrencyCode,
197
- MimeType,
198
- ImageMimeType,
199
- DocumentMimeType,
200
158
  } from "@standards/constants";
201
159
  ```
202
160