@simplysm/core-common
v13.0.67
Published
심플리즘 패키지 - 코어 모듈 (common)
Readme
@simplysm/core-common
A common utility package for the Simplysm framework. As a neutral base module usable in both Node.js and browser environments, it provides date/time types, error classes, object/array/string utilities, JSON serialization, ZIP processing, prototype extensions, and more.
Installation
npm install @simplysm/core-common
# or
pnpm add @simplysm/core-commonInitialization
Import the package at your application entry point (e.g., index.ts, main.ts):
import "@simplysm/core-common";This import globally activates Array, Map, and Set prototype extensions.
To use extension methods (getOrCreate(), toggle(), etc.), you must import this at app startup.
Main Modules
Errors
SdError- Base error class with cause chain trackingArgumentError- Argument validation error with YAML formattingNotImplementedError- Indicates unimplemented functionalityTimeoutError- Timeout error
Custom Types
DateTime- Date + time (millisecond precision, local timezone)DateOnly- Date only (no time)Time- Time only (no date, 24-hour cycle)Uuid- UUID v4 (cryptographically secure)LazyGcMap- Map with auto-expiration (LRU style)
Features
DebounceQueue- Async debounce queue (executes only last request)SerialQueue- Async serial queue (sequential execution)EventEmitter- EventTarget wrapper with type-safe events
ZIP
ZipArchive- ZIP file compression/decompression utility
Object Utilities
objClone- Deep clone (supports circular references, custom types)objEqual- Deep comparison with optionsobjMerge- Deep merge (source + target)objMerge3- 3-way merge with conflict detectionobjOmit- Exclude specific keysobjOmitByFilter- Exclude keys matching a predicateobjPick- Select specific keysobjGetChainValue- Query value by chain pathobjGetChainValueByDepth- Query value by descending the same key repeatedlyobjSetChainValue- Set value by chain pathobjDeleteChainValue- Delete value by chain pathobjClearUndefined- Delete keys withundefinedvalues (mutates original)objClear- Delete all keys from an object (mutates original)objNullToUndefined- Recursively convert null to undefined (mutates original)objUnflatten- Convert dot-notation flat object to nested objectobjKeys- Type-safeObject.keysobjEntries- Type-safeObject.entriesobjFromEntries- Type-safeObject.fromEntriesobjMap- Transform each entry of object
JSON Utilities
jsonStringify- JSON serialization with custom type supportjsonParse- JSON deserialization with custom type restoration
XML Utilities
xmlParse- Parse XML string to objectxmlStringify- Serialize object to XML string
String Utilities
strGetSuffix- Korean postposition handlingstrReplaceFullWidth- Convert full-width to half-widthstrToPascalCase- PascalCase conversionstrToCamelCase- camelCase conversionstrToKebabCase- kebab-case conversionstrToSnakeCase- snake_case conversionstrIsNullOrEmpty- Check for undefined/null/empty (type guard)strInsert- Insert at position in string
Number Utilities
numParseInt- Parse string to integernumParseFloat- Parse string to floatnumParseRoundedInt- Round float and return integernumFormat- Thousands separator formattingnumIsNullOrEmpty- Check for undefined/null/0 (type guard)
Date/Time Formatting
formatDate- Convert date/time to formatted stringnormalizeMonth- Normalize year/month/day when setting monthconvert12To24- Convert 12-hour to 24-hour format
Byte Utilities
bytesConcat- Concatenate multiple Uint8ArraysbytesToHex- Convert Uint8Array to hex stringbytesFromHex- Convert hex string to Uint8ArraybytesToBase64- Convert Uint8Array to base64 stringbytesFromBase64- Convert base64 string to Uint8Array
Async Wait
Worker Data Conversion
transferableEncode- Serialize custom types for Worker transfertransferableDecode- Deserialize Worker data to custom types
Path Utilities
pathJoin- Combine paths (POSIX-style only)pathBasename- Extract filenamepathExtname- Extract extension
Template Literal Tags
js- JavaScript code highlightingts- TypeScript code highlightinghtml- HTML markup highlightingtsql- MSSQL T-SQL highlightingmysql- MySQL SQL highlightingpgsql- PostgreSQL SQL highlighting
Other Utilities
getPrimitiveTypeStr- InferPrimitiveTypeStrfrom runtime valueenv- Environment variable object
Array Extensions
Query
Filtering
filterExists- Removenull/undefinedofType- Filter by typefilterAsync- Async filter
Mapping/Transformation
mapAsync- Async mapping (sequential)mapMany- Flatten nested arrays and remove null/undefinedmapManyAsync- Async mapManyparallelAsync- Parallel async mapping
Grouping
groupBy- Group by keytoMap- Convert to MaptoMapAsync- Async Map conversiontoArrayMap- Convert toMap<K, V[]>toSetMap- Convert toMap<K, Set<V>>toMapValues- Aggregate Map by grouptoObject- Convert toRecord<string, V>toTree- Convert to tree structure
Deduplication
distinct- Remove duplicates (new array)distinctThis- Remove duplicates (modify original)
Sorting
orderBy- Ascending sort (new array)orderByDesc- Descending sort (new array)orderByThis- Ascending sort (modify original)orderByDescThis- Descending sort (modify original)
Comparison/Merging
diffs- Compare differences between arraysoneWayDiffs- One-way diff comparisonmerge- Merge arrays
Aggregation
Mutation
insert- Insert at specific positionremove- Remove item or items matching predicatetoggle- Toggle itemclear- Remove all itemsshuffle- Shuffle array
Map Extensions
getOrCreate- Get or create and return valueupdate- Update value using function
Set Extensions
Types
Bytes- Alias forUint8ArrayPrimitiveTypeStr- Primitive type string keysPrimitiveTypeMap- Mapping from type string to typePrimitiveType- Union of all primitive types (includesundefined)DeepPartial- Recursively convert properties to optionalType- Constructor typeObjUndefToOptional- Convertundefinedproperties to optionalObjOptionalToUndef- Convert optional properties torequired + undefinedEqualOptions- Options forobjEqualObjMergeOptions- Options forobjMergeObjMerge3KeyOptions- Per-key options forobjMerge3DtNormalizedMonth- Return type ofnormalizeMonthZipArchiveProgress- Progress info forZipArchive.extractAllArrayDiffsResult- Result type ofArray.diffs()ArrayDiffs2Result- Result type ofArray.oneWayDiffs()TreeArray- Result type ofArray.toTree()ComparableType- Union of types usable for sorting/comparison
Caveats
Prototype Extension Conflicts
This package extends Array, Map, and Set prototypes. Conflicts may occur when used with other libraries that extend the same method names. In case of conflict, the last defined implementation is applied based on load order.
Timezone Handling
When using DateOnly.parse(), DateTime.parse():
yyyy-MM-dd,yyyyMMddformat: parse directly from string (no timezone influence)- ISO 8601 format (
2024-01-15T00:00:00Z): interpret as UTC then convert to local
When server and client timezones differ, actively use yyyy-MM-dd format.
Memory Management (LazyGcMap)
LazyGcMap has an internal GC timer, so it must be cleaned up.
// using statement (recommended)
// gcInterval: GC execution interval (ms), expireTime: item expiration time (ms)
using map = new LazyGcMap({ gcInterval: 10000, expireTime: 60000 }); // GC every 10 seconds, expire after 60 seconds
// Or explicit dispose() call
const map = new LazyGcMap({ gcInterval: 10000, expireTime: 60000 }); // GC every 10 seconds, expire after 60 seconds
try {
// ... use
} finally {
map.dispose();
}jsonStringify's type Reserved Word
jsonStringify/jsonParse uses objects with __type__ and data keys for type restoration.
Be careful as user data in the form { __type__: "DateTime", data: "..." } may be unintentionally type-converted.
Circular References
objClone: supports circular references (tracked with WeakMap)jsonStringify: throws TypeError on circular referencetransferableEncode: throws TypeError on circular reference (includes path information)
License
Apache-2.0
