Releases: saqqdy/js-cool
Release list
6.0.0
⚠️ BREAKING CHANGES
-
Build System: Migrated from Rollup to Rolldown
- Output files:
index.js(CJS),index.mjs(ESM),index.iife.js,index.iife.min.js - CDN global variable changed from
JsCooltojsCool
- Output files:
-
Deprecated Functions Removed:
getAppVersion→appVersiongetOsVersion→osVersiongetDirParam→getDirParamsgetScrollPosition→scroll.getPositionisDigitals→ use/^\d*$/.test(str)pattern→validationtrim→String.prototype.trim()isExitsVariable→getGlobal(name) != nullgetQueryParam→url.get()ornew Url(url).get()getQueryParams→url.parse()ornew Url(url).toObject()getUrlParam→url.get()ornew Url(url).get()getUrlParams→url.parse()ornew Url(url).toObject()parseUrlParam→url.parse()spliceUrlParam→url.stringify()ornew Url(url).set()setCache→storage.local.set()getCache→storage.local.get()delCache→storage.local.delete()setSession→storage.session.set()getSession→storage.session.get()delSession→storage.session.delete()setCookie→storage.cookie.set()getCookie→storage.cookie.get()getCookies→storage.cookie.getAll()delCookie→storage.cookie.delete()mapTemplate→template()(v6.0.0, usetemplatefunction)
-
Module Renamed:
client→ua -
Type Change:
base64ToFile()returnsFile | Blob(IE11 returns Blob)
🚀 Features
-
New
binaryModule: Unified binary data conversion API- Chainable conversion:
binary.from(blob).toBase64(),binary.from(file).toArrayBuffer(), etc. - Type detection:
isBlob(),isFile(),isArrayBuffer(),isDataURL(),isBase64() - Sub-modules:
binary.base64: encode/decode, toBlob/toArrayBuffer/toDataURL/toFilebinary.blob: toBase64/toArrayBuffer/toDataURL/toFile/toURL, concat, slicebinary.arrayBuffer: toBase64/toDataURL/toBlob/toString/toHexbinary.file: toBase64/toArrayBuffer/toBlobbinary.text: encode/decode, toBase64/fromBase64binary.hex: encode/decodebinary.dataURL: parse/build/isValidbinary.svg: toBlob/toDataURL/toURLbinary.url: toBlob/toDataURLbinary.hash: md5, sha1, sha256, crc32binary.meta: get file metadata (size, mime, extension, isImage, etc.)
- Utility methods:
compare(),clone(),download(),parse() - Full TypeScript support with comprehensive type definitions
- IE11 compatibility built-in
- Recommended replacement for:
encodeBase64,decodeBase64,arrayBufferToBase64,base64ToArrayBuffer,base64ToBlob,blobToBase64,blobToArrayBuffer,fileToBase64,base64ToFile,svgToBlob,urlToBlob,arrayBufferToBlob,blobToUrl
- Chainable conversion:
-
New
uaModule: Comprehensive User-Agent detection- Device, OS, browser, environment detection
- Quick checks:
isMobile(),isWeChat(),isiOS(),isHarmonyOS(), etc. - Type exports:
UA,UAInfo,DeviceInfo,OSInfo,BrowserInfo,EnvironmentInfo
-
New
urlModule: Chainable URL builder with URLSearchParams-like APIUrlclass: Enhanced URL builder that parses both search and hash parameters- Static methods:
get(),set(),parse(),stringify(), etc. - Descriptive function aliases:
parseQueryString,stringifyQueryString,getQueryParamValue,setQueryParam, etc. - URL property extraction:
getOrigin(),getHost(),getHostname(),getPathname(),getSearch(),getHash()
-
New
scrollModule:getPosition(),getProgress(),scrollTo(),lock(),unlock(), etc. -
New
storageModule: Unified storage namespace with consistent APIstorage.local: localStorage with expiration, generic types, and error handlingstorage.session: sessionStorage with same features as localstorage.cookie: Cookie with full options support (path,domain,secure,sameSite)- Methods:
set(),get(),delete(),has(),keys(),clear(),length - Error classes:
StorageQuotaError,StorageUnavailableError - Subpath import:
import { storage } from 'js-cool/storage'
-
New
patternsModule: Unified validation and UA patternsvalidation.email,validation.mobile,validation.idCard, etc.DEVICE_PATTERNS,OS_PATTERNS,BROWSER_PATTERNS,ENV_PATTERNSextractpatterns:number,version,integer,decimal,positiveInteger(NEW)
-
50+ New Functions:
- Array:
chunk,flatten,groupBy,keyBy,countBy,sample,sampleSize,intersect,intersectionBy,union,unionBy,differenceBy,drop,dropRight,take,takeRight,findIndex,findLastIndex,zip,unzip - Number:
sum,average,clamp,round,inRange - String:
kebabCase,snakeCase,truncate,capitalize,lowerFirst,words,template - Object:
omit,pick,isEmpty,isNil,mapKeys,mapValues,invert,mergeWith,transform - Validate:
isEmail,isPhone,isURL,isIDCard,isCreditCard - Color:
isLightColor,hexToRGB,rgbToHSL,lighten,darken - Date:
isToday,formatDate,dateDiff,relativeTime,getDaysInMonth - Async:
debounce,throttle,retry
- Array:
-
New String Functions (v6.0.0):
changeCase: Unified case conversion API (camel, kebab, snake, pascal, constant, dot, title, swap, etc.)constantCase: Convert to CONSTANT_CASEdotCase: Convert to dot.casepascalCase: Convert to PascalCasetitleCase: Convert to Title CaseswapCase: Swap case of each characterreverse: Reverse string (Unicode aware)count: Count substring occurrences
-
Enhanced Functions:
getNumber: Addedtype,multiple,decimalsoptionstoThousands: Addedseparator,decimals,prefix,suffixoptionscamel2Dash: Improved consecutive uppercase handling (XMLParser → xml-parser)template: Added function resolver support for dynamic valuessortPinyin: Optimized with accurate Chinese character detection using Unicode ranges (CJK Unified Ideographs), propernull/undefinedhandling, cachedIntl.Collatorinstance for better performance, and newsortPinyin.sort(array)methoddebounce: Refactored to share core logic withthrottle, both functions now use the same internal implementation,throttleis now a wrapper arounddebouncewithmaxWait: wait, improved TypeScript types withDebouncedFunction<T>interfacegetCHSLength: Improved full-width character detection, now correctly detects emoji and other full-width characters as 2 bytes, exportedisFullWidth()helper functioncutCHSString: Refactored to usegetCHSLengthinternally, more accurate byte-length calculation, better handling of edge casesrandomNumber: Fixed distribution bias usingMath.floor()instead ofMath.round()for uniform distributionrandomNumbers: Improved distribution algorithm for better uniformityrandomColor: Added alpha channel support withalphaoption (boolean for random, 0-255 for specific), added options object APIrandomString: Addedsecureoption for cryptographically secure random generation usingcrypto.getRandomValues()
-
New IE11 Compatibility Functions:
arrayFrom: IE11-compatibleArray.from()repeatString: IE11-compatibleString.prototype.repeat()
-
IE11 Compatibility: Built-in support without external polyfills
- New
hasOwn()compatibility method forObject.hasOwn()
- New
-
Rolldown Migration: ~110ms build time (was ~6-8s)
-
VitePress Docs: Bilingual documentation site
📦 Build Output
| File | Format | Size |
|---|---|---|
index.js |
CJS | ~159KB |
index.mjs |
ESM | ~154KB |
index.iife.min.js |
IIFE (minified) | ~47KB |
📖 Quick Migration
// v5.x
import { client, pattern } from 'js-cool'
client.isMobile()
pattern.email.test('user@example.com')
// v6.x
import { ua, validation } from 'js-cool'
ua.isMobile()
validation.email.test('user@example.com')
// New binary module (v6.0.0)
import { binary } from 'js-cool'
// Chainable conversion
const base64 = await binary.from(blob).toBase64()
const arrayBuffer = await binary.from(file).toArrayBuffer()
const { url, revoke } = await binary.from(base64String).toURL()
// Hash functions
const sha256 = await binary.hash.sha256('Hello World')
const md5 = await binary.hash.md5(data)
// File metadata
const meta = binary.meta.get(file)
// { size, mime, name, extension, isImage, isVideo, isAudio, isText }Full Changelog: 5.23.2...6.0.0
v5.23.2
Added
- Add vitest testing framework with comprehensive unit tests for all functions
Fixed
- Fix bugs in
browserVersion,compareVersion,nextVersion,randomString,safeStringify - Fix JSDoc garbled characters in
decodeUtf8
Docs
- Rewrite README-zh_CN.md with comprehensive API documentation
- Optimize JSDoc for all functions in src directory with comprehensive
@exampletags - Add multiple usage examples covering various scenarios for each function
- Improve parameter and return value documentation
Full Changelog: 5.23.1...5.23.2
v5.23.1
- docs work
- upgrade all packages
What's Changed
- Bump typescript and typedoc by @dependabot in #97
Full Changelog: 5.23.0...5.23.1
v5.23.0
punctualTimergot returns of PunctualTimerReturns
Full Changelog: 5.22.1...5.23.0
v5.22.1
- fix bugs of
nextVersion
Full Changelog: 5.22.0...5.22.1
v5.22.0
- new
isNumberBrowserfunction, see: isNumberBrowser - Default value of agent string for
getOsVersionandgetAppVersionchanged to navigator.appVersion.
Full Changelog: 5.21.2...5.22.0
v5.21.2
patternsupport mac/ip4/ip4_pri
What's Changed
- Bump @microsoft/api-extractor from 7.46.2 to 7.47.6 by @dependabot in #96
Full Changelog: 5.21.1...5.21.2
v5.21.1
osVersionsupport Harmony
Full Changelog: 5.21.0...5.21.1
v5.21.0
spliceUrlParamBreaking change: SpliceUrlParamOptions
Full Changelog: 5.20.0...5.21.0