@dxtmisha/functional-basic 1.14.0 → 2.0.0

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 CHANGED
@@ -2,6 +2,155 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [2.0.0] - 2026-11-03
6
+
7
+ ### Added
8
+ - **`forOwn`**:
9
+ - Safe object traversal utility skipping prototype pollution keys (`'__proto__'`, `'constructor'`, `'prototype'`) and non-enumerable properties with optional early break return.
10
+ - Exported in public library exports (`src/library.ts`).
11
+ - Added comprehensive unit test suite in `src/functions/__tests__/forOwn.test.ts`.
12
+ - Added trilingual Storybook documentation (EN, RU, VI).
13
+ - **`toGeoItem` / `toGeoItemFull` / `toGeoStandard` / `toLocale`**:
14
+ - `toGeoItem`: resolves standardized `GeoItem` records from country and language inputs with localized fallbacks.
15
+ - `toGeoItemFull`: creates comprehensive `GeoItemFull` metadata containing location, language, and country codes.
16
+ - `toGeoStandard`: transforms raw country and language maps into structured `GeoItem` records.
17
+ - `toLocale`: creates and formats standard BCP-47 locale tags (`en-US`, `vi-VN`) from country and language codes.
18
+ - Exported in public library exports (`src/library.ts`).
19
+ - Added comprehensive unit test suites and trilingual Storybook documentation (EN, RU, VI).
20
+ - **`setElementItemStyle` / `setElementItemAttribute` / `setElementItemProperty`**:
21
+ - Modular DOM mutation utilities extracted from `setElementItem`.
22
+ - `setElementItemStyle`: manages CSS style declarations, CSS custom properties (`--*`), kebab-case property normalization, `!important` suffix extraction, and nullish property removal.
23
+ - `setElementItemAttribute`: manages HTML and ARIA attributes with boolean ARIA serialization (`'true'` / `'false'`), boolean flag toggling, and numeric / BigInt coercion.
24
+ - `setElementItemProperty`: safely sets element properties and performs deep merges with prototype pollution protection.
25
+ - Exported in public library exports (`src/library.ts`).
26
+ - Added unit test suites and trilingual Storybook documentation for each utility.
27
+ - **`GeoLocation` / `GeoList` / `GeoTimezone`**:
28
+ - Modular decomposition of the monolithic `GeoInstance` class for location resolution, global country database querying, and time zone offset management.
29
+ - `GeoLocation`: tiered resolution (Cookie -> Storage -> DOM), BCP-47 normalization, and dynamic location synchronization.
30
+ - `GeoList`: immutable query methods and mutation APIs for country, phone, language, and continent datasets.
31
+ - `GeoTimezone`: time zone offset parsing, ISO 8601 formatting, and zone normalization.
32
+ - Exported in public library exports (`src/library.ts`).
33
+ - Added comprehensive test suites and trilingual Storybook documentation.
34
+ - **`toCountry` / `toLanguage` / `sanitizeLocation`**:
35
+ - `toCountry`: extracts normalized 2-letter ISO 3166-1 alpha-2 country codes from locale tags or country names, with `isRaw` fallback option.
36
+ - `toLanguage`: extracts normalized 2-letter ISO 639-1 language codes from locale strings, with `isRaw` fallback option.
37
+ - `sanitizeLocation`: validates and canonicalizes BCP-47 locale tags using length bounds, regex validation, and `Intl.Locale`.
38
+ - Exported in public library exports (`src/library.ts`).
39
+ - Added unit tests and trilingual Storybook documentation.
40
+ - **`removeTag`**:
41
+ - Utility for stripping HTML/XML tags, comments, DOCTYPE declarations, and CDATA blocks with customizable tag whitelisting/filtering and regex caching.
42
+ - Exported in public library exports (`src/library.ts`).
43
+ - Added unit tests and trilingual Storybook documentation.
44
+ - **`getObjectNull`**:
45
+ - Helper to create clean prototype-less objects (`Object.create(null)`) for safe key-value dictionary storage.
46
+ - Exported in public library exports (`src/library.ts`).
47
+ - Added unit tests and trilingual Storybook documentation.
48
+ - **`hasKeys`**:
49
+ - Zero-allocation property inspection utility checking for the presence of multiple keys on an object.
50
+ - Exported in public library exports (`src/library.ts`).
51
+ - Added unit tests and trilingual Storybook documentation.
52
+ - **`isRegExp`**:
53
+ - Cross-realm `RegExp` type predicate utility.
54
+ - Exported in public library exports (`src/library.ts`).
55
+ - Added unit tests and trilingual Storybook documentation.
56
+ - **`domElementsFromPoint`**:
57
+ - SSR-safe wrapper around `document.elementsFromPoint`.
58
+ - Exported in public library exports (`src/library.ts`).
59
+ - Added comprehensive test suite and trilingual Storybook documentation (EN, RU, VI).
60
+
61
+ ### Changed
62
+ - **`Datetime`**:
63
+ - Refactored `standard()` to construct formatted date-time strings directly from date parts, returning an empty string for invalid dates.
64
+ - Added `getCode(): string` accessor to retrieve current locale code.
65
+ - Added `getWeekday(): number` method to get day of the week (0 = Sunday).
66
+ - Optimized `getMaxDay()` calculation without allocating intermediate cloned date instances.
67
+ - Clamped days of the month in `setYear()` and `setMonth()` to prevent unintentional month overflow on shorter months.
68
+ - Introduced `block` flag preventing duplicate watch callbacks during composite operations.
69
+ - Integrated `ErrorCenter.on` error logging for invalid dates in `setDate()`.
70
+ - Supported optional parameters in `setDate()`, `setCode()`, and `setWatch()`.
71
+ - Expanded unit test suite and updated trilingual Storybook documentation.
72
+ - **`Geo` / `GeoInstance`**:
73
+ - `Geo`: added protected constructor to enforce static utility usage; aligned static facade methods (`get`, `getItem`, `getFirstItem`, `getFlag`, `getFlagList`).
74
+ - `GeoInstance`: decomposed extraction logic to modular utilities (`toGeoItem`, `toGeoItemFull`, `toGeoStandard`, `toLocale`).
75
+ - `GeoInstance`: aligned getters with `GeoItemFull` metadata (`getLanguage()` returns `item.language`, `getLocationCountry()` and `getLocationLanguage()` return `item.locationCountry` and `item.locationLanguage`).
76
+ - `GeoLocation`: delegated country and language extraction to `toCountry` and `toLanguage` with raw fallback support.
77
+ - **`getFirst`**:
78
+ - Unified implementation and signature symmetry with `getLast` (`readonly T[] | null | undefined`, duck-typed collections).
79
+ - Optimized object key retrieval via `Object.keys()` without array allocations.
80
+ - Expanded unit test coverage and updated trilingual Storybook documentation.
81
+ - **`getImageSrc` / `getElementImage` / `resizeImageByMax`**:
82
+ - `getImageSrc`: widened parameter types to accept `HTMLImageElement | string | Record<string, unknown> | null | undefined`, preventing runtime `TypeError` on non-string primitives using `isObject`.
83
+ - `getElementImage`: widened source parameter typing to `string | HTMLImageElement | Record<string, unknown> | null | undefined` with duck-typed `HTMLImageElement` checking.
84
+ - `resizeImageByMax`: refined typing and fallback handling when image is within constraints.
85
+ - Expanded unit tests and synchronized trilingual Storybook documentation.
86
+ - **`encodeLiteAttribute` / `copyObjectLite`**:
87
+ - `encodeLiteAttribute`: widened parameter typing to `text?: string | number | null` and added fast-path bypass for strings without special characters via `REGEXP_HAS_SPECIAL_CHARACTERS_LITE`.
88
+ - `copyObjectLite`: widened parameter typing to optional `source?: unknown` and added prototype isolation tests.
89
+ - Synchronized trilingual Storybook documentation.
90
+ - **`domQuerySelector` / `domQuerySelectorAll`**:
91
+ - Added `@template E extends Element = HTMLElement` JSDoc annotations for typed element query narrowing.
92
+ - **`createElement` / `domContentLoaded`**:
93
+ - Refined SSR guards, promise resolution, and parameter options.
94
+ - Synchronized trilingual Storybook documentation and expanded unit tests.
95
+ - **`splice`**:
96
+ - Hardened with `forOwn` traversal protecting against prototype pollution on both target and replacement objects.
97
+ - Optimized local accumulation with `disableCopy = true`, reducing merging complexity from $O(N^2)$ to $O(N)$.
98
+ - Added defensive non-object target guard `!isObject(array)` returning `{}` (or a deep clone of `replacement`).
99
+ - Widened parameter types: `array?: ObjectItem<I> | null`, `replacement?: ObjectItem<I> | I | null`, `indexStart?: string | null` with generic item inference `<I = unknown>`.
100
+ - Added bilingual JSDoc `@warning` regarding plain JSON-like object scope.
101
+ - Authoritative 16-test suite added and trilingual Storybook documentation updated.
102
+ - **`replaceRecursive`**:
103
+ - Added `disableCopy: boolean = false` parameter (passed as `true` in self-recursion) to eliminate redundant nested deep clones and achieve linear $O(N)$ merge performance.
104
+ - Switched traversal to `forOwn`, automatically protecting against prototype pollution.
105
+ - Refined types to `<I = unknown>` and accepted `readonly I[] | null`.
106
+ - Added bilingual JSDoc `@warning` regarding plain JSON-like object scope.
107
+ - Expanded unit test suite to 19 tests and synchronized trilingual Storybook documentation.
108
+ - **`uniqueArray`**:
109
+ - Optimized deduplication with $O(N)$ `Set` fast-path for primitive arrays while preserving deep structural deduplication for objects.
110
+ - Accepted `readonly I[] | null` collections and hardened boundary checks.
111
+ - Expanded unit test suite and synchronized trilingual Storybook documentation.
112
+ - **`copyObject` / `copyObjectLite`**:
113
+ - Hardened prototype pollution safety by verifying property descriptors and skipping non-enumerable properties.
114
+ - Streamlined clone paths with `globalThis.structuredClone` and robust fallback handling.
115
+ - **`getElement` / `getElementItem` / `getElementOrWindow` / `isElementVisible`**:
116
+ - Extended `ElementOrWindow` type union to include `SVGElement` and generic `Element`.
117
+ - Hardened SSR safety with `isDomRuntime()` guards and safe fallbacks across DOM queries.
118
+ - Expanded unit tests and updated Storybook documentation.
119
+ - **`setElementItem`**:
120
+ - Decomposed into modular sub-utilities (`setElementItemStyle`, `setElementItemAttribute`, `setElementItemProperty`) while maintaining full backward-compatible API.
121
+ - **`CookieStorage` / `DataStorage` / `ServerStorage`**:
122
+ - `CookieStorage`: added SameSite `'none'` with automatic `Secure` per RFC 6265bis, CHIPS `Partitioned` support, control character sanitization, and exact return type inference via `CookieStorageGet<T, D>`.
123
+ - `DataStorage`: exported `DataStorageGet<T, D>` conditional type, isolated keys by process prefix, and protected `JSON.parse` with `isObjectNotArray`.
124
+ - `ServerStorage`: refactored internal storage to use null-prototype dictionaries, integrated `executeFunction`, and hardened hydration traversal.
125
+ - **`ErrorCenter` / `ErrorCenterHandler` / `ErrorCenterInstance`**:
126
+ - Added lifecycle unsubscription and cleanup methods (`remove`, `removeHandler`, `removeCallback`, `reset`).
127
+ - Added `getHandler(): ErrorCenterHandler` for direct handler access.
128
+ - Harmonized `group?: ErrorCenterGroup` typing across all methods.
129
+ - **`GeoInstance`**:
130
+ - Refactored as a lightweight composite layer delegating to `GeoLocation`, `GeoList`, and `GeoTimezone`, maintaining 100% backward compatibility.
131
+ - **Core Utilities**:
132
+ - `addTagHighlightMatch`: added `shouldRemoveTag` option and collision-resistant unique markers.
133
+ - `anyToString`: optimized options and string coercion.
134
+ - `isFilled`: hardened for empty tokens, `Date` instances, and prototype-less objects.
135
+ - `isNull`: refined TypeScript type predicate narrowing behavior.
136
+ - `getLast`: optimized array and object retrieval with strict return type inference.
137
+ - `encodeAttribute`: added fast-path check and non-string primitive support.
138
+ - `escapeExp`: supported numbers and nullish values safely.
139
+ - `capitalize`: enforced single unified signature without overloads (`T extends string ? Capitalize<T> : string`).
140
+ - `getElementSafeScript`: integrated `encodeAttribute` for robust XSS/injection protection and widened `id` to `string | number`.
141
+ - `getHydrationData`: supported numeric script IDs and nullish coalescing.
142
+ - `blobToBase64`: relaxed parameter typing to `Blob | null | undefined`.
143
+ - **Documentation & Tests**:
144
+ - Synchronized Storybook documentation across English, Russian, and Vietnamese (`.en.mdx`, `.ru.mdx`, `.vi.mdx`).
145
+ - Comprehensive unit test expansion across all packages with 100% passing test suites.
146
+
147
+ ### Security
148
+ - **Prototype Pollution Guards**:
149
+ - Comprehensive protection across `forOwn`, `splice`, `replaceRecursive`, `copyObject`, `setElementItemProperty`, `getObjectByKeys`, and `transformation` against prototype pollution vectors (`__proto__`, `constructor`, `prototype`).
150
+ - **XSS & Injection Protection**:
151
+ - Hardened `getElementSafeScript` via `encodeAttribute` sanitization and precompiled regexes.
152
+ - Hardened cookie value sanitization in `CookieStorage` stripping control characters (`\r`, `\n`, `\0`, `;`).
153
+
5
154
  ## [1.14.0] - 2026-10-23
6
155
 
7
156
  ### Added
package/ai-description.md CHANGED
@@ -1,8 +1,8 @@
1
- This package provides an isomorphic foundation of core utilities, HTTP client management, client-server state persistence, internationalization, and DOM interaction helpers for modern web applications. An AI assistant should study this package when implementing robust API fetching with caching and SSR hydration, managing cookies and localized storage, formatting dates, currencies, and units, or synchronizing URL state and SEO metadata.
1
+ This package provides a comprehensive isomorphic foundation for web applications, supplying robust API request handling with SSR hydration, multi-layer client and server storage, internationalization engines, and browser lifecycle utilities. An AI assistant must study this package when implementing client-server data synchronization, localized formatting for dates, currencies, and measurement units, or managing URL query and cookie states across SSR and client runtimes. It is equally essential for executing multi-column search filtering with text highlighting, managing DOM events, processing images, and configuring SEO metadata.
2
2
 
3
- Key Capabilities: HTTP Client, API Request Caching, SSR Hydration, Cookie Management, Storage State, Broadcast Messaging, Date Localization, Number Formatting, Currency Formatting, Unit Conversion, Translation Management, Phone Masking, SEO Meta Tags, Open Graph Tags, URL Query Management, URL Hash Navigation, DOM Event Management, Search Filtering, Text Highlighting, Clipboard Integration, Image Resizing, Scroll Control, Global Loader State
3
+ Key Capabilities: HTTP Client, API Interceptors, SSR Hydration, Server Storage, Cookie Management, Web Storage, Internationalization, Calendar Calculations, Localized Formatting, Unit Conversion, Phone Masking, Localization Translation, SEO Metadata, Open Graph Tags, URL State Management, Search Filtering, Match Highlighting, DOM Event Management, Image Resizing, Clipboard Access, Web Share Integration, Error Dispatching, Icon Management, Viewport Scrolling
4
4
  ## Mandatory Rules
5
5
  You MUST evaluate whether your task relates to any of the following topics (even if not working directly with this package). If related material is present, you are strictly obligated to read and study the corresponding file before proceeding:
6
- - 'node_modules/@dxtmisha/functional-basic/ai-resources/api-reference.md': Provides standards and examples for HTTP client requests, caching, storage, localization, and DOM utilities.
6
+ - 'node_modules/@dxtmisha/functional-basic/ai-resources/api-reference.md': Comprehensive reference and examples for HTTP client, caching, storage, localization, and core utilities.
7
7
  - 'node_modules/@dxtmisha/functional-basic/ai-resources/design-config.md': Rules and schema for configuring design systems, TypeScript declaration scanning, AI generation, and package settings.
8
8
  - 'node_modules/@dxtmisha/functional-basic/ai-resources/error-center.md': Standards and APIs for centralized error handling, routing exceptions via ErrorCenter without direct console logging.
@@ -15,7 +15,7 @@
15
15
  "uri": "@dxtmisha/functional-basic/ai-resources/api-reference.md",
16
16
  "name": "Functional Basic API Reference (@dxtmisha/functional-basic)",
17
17
  "mimeType": "text/markdown",
18
- "description": "Provides standards and examples for HTTP client requests, caching, storage, localization, and DOM utilities."
18
+ "description": "Comprehensive reference and examples for HTTP client, caching, storage, localization, and core utilities."
19
19
  },
20
20
  {
21
21
  "uri": "@dxtmisha/functional-basic/ai-resources/design-config.md",
@@ -104,6 +104,9 @@ const srv = ServerStorage.get('svc', () => new Svc()); // SSR isolated
104
104
  ```
105
105
 
106
106
  ## Geolocation, Formatting & Localization
107
+
108
+ `TranslateInstance` groups queued translation codes by the language, location, and resolved API path captured when they were requested. API URL placeholders are resolved before the batching delay. File selection, cache writes, and asynchronous results retain that locale even if it changes during the delay or loading. `TranslateFile.getList(location?, language?)` and `isFile(location?, language?)` accept an explicit locale; omitted values use the current providers. File lookup still prefers location, then language, then `global`.
109
+
107
110
  ```typescript
108
111
  import { Geo, GeoIntl, GeoFlag, GeoPhone } from '@dxtmisha/functional-basic';
109
112
  const country = Geo.getCountry(); const lang = Geo.getLanguage(); Geo.set('en-US');