Skip to content

Releases: saqqdy/js-cool

6.0.0

Choose a tag to compare

@saqqdy saqqdy released this 05 Apr 13:31

⚠️ 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 JsCool to jsCool
  • Deprecated Functions Removed:

    • getAppVersionappVersion
    • getOsVersionosVersion
    • getDirParamgetDirParams
    • getScrollPositionscroll.getPosition
    • isDigitals → use /^\d*$/.test(str)
    • patternvalidation
    • trimString.prototype.trim()
    • isExitsVariablegetGlobal(name) != null
    • getQueryParamurl.get() or new Url(url).get()
    • getQueryParamsurl.parse() or new Url(url).toObject()
    • getUrlParamurl.get() or new Url(url).get()
    • getUrlParamsurl.parse() or new Url(url).toObject()
    • parseUrlParamurl.parse()
    • spliceUrlParamurl.stringify() or new Url(url).set()
    • setCachestorage.local.set()
    • getCachestorage.local.get()
    • delCachestorage.local.delete()
    • setSessionstorage.session.set()
    • getSessionstorage.session.get()
    • delSessionstorage.session.delete()
    • setCookiestorage.cookie.set()
    • getCookiestorage.cookie.get()
    • getCookiesstorage.cookie.getAll()
    • delCookiestorage.cookie.delete()
    • mapTemplatetemplate() (v6.0.0, use template function)
  • Module Renamed: clientua

  • Type Change: base64ToFile() returns File | Blob (IE11 returns Blob)

🚀 Features

  • New binary Module: 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/toFile
      • binary.blob: toBase64/toArrayBuffer/toDataURL/toFile/toURL, concat, slice
      • binary.arrayBuffer: toBase64/toDataURL/toBlob/toString/toHex
      • binary.file: toBase64/toArrayBuffer/toBlob
      • binary.text: encode/decode, toBase64/fromBase64
      • binary.hex: encode/decode
      • binary.dataURL: parse/build/isValid
      • binary.svg: toBlob/toDataURL/toURL
      • binary.url: toBlob/toDataURL
      • binary.hash: md5, sha1, sha256, crc32
      • binary.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
  • New ua Module: 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 url Module: Chainable URL builder with URLSearchParams-like API

    • Url class: 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 scroll Module: getPosition(), getProgress(), scrollTo(), lock(), unlock(), etc.

  • New storage Module: Unified storage namespace with consistent API

    • storage.local: localStorage with expiration, generic types, and error handling
    • storage.session: sessionStorage with same features as local
    • storage.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 patterns Module: Unified validation and UA patterns

    • validation.email, validation.mobile, validation.idCard, etc.
    • DEVICE_PATTERNS, OS_PATTERNS, BROWSER_PATTERNS, ENV_PATTERNS
    • extract patterns: 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
  • New String Functions (v6.0.0):

    • changeCase: Unified case conversion API (camel, kebab, snake, pascal, constant, dot, title, swap, etc.)
    • constantCase: Convert to CONSTANT_CASE
    • dotCase: Convert to dot.case
    • pascalCase: Convert to PascalCase
    • titleCase: Convert to Title Case
    • swapCase: Swap case of each character
    • reverse: Reverse string (Unicode aware)
    • count: Count substring occurrences
  • Enhanced Functions:

    • getNumber: Added type, multiple, decimals options
    • toThousands: Added separator, decimals, prefix, suffix options
    • camel2Dash: Improved consecutive uppercase handling (XMLParser → xml-parser)
    • template: Added function resolver support for dynamic values
    • sortPinyin: Optimized with accurate Chinese character detection using Unicode ranges (CJK Unified Ideographs), proper null/undefined handling, cached Intl.Collator instance for better performance, and new sortPinyin.sort(array) method
    • debounce: Refactored to share core logic with throttle, both functions now use the same internal implementation, throttle is now a wrapper around debounce with maxWait: wait, improved TypeScript types with DebouncedFunction<T> interface
    • getCHSLength: Improved full-width character detection, now correctly detects emoji and other full-width characters as 2 bytes, exported isFullWidth() helper function
    • cutCHSString: Refactored to use getCHSLength internally, more accurate byte-length calculation, better handling of edge cases
    • randomNumber: Fixed distribution bias using Math.floor() instead of Math.round() for uniform distribution
    • randomNumbers: Improved distribution algorithm for better uniformity
    • randomColor: Added alpha channel support with alpha option (boolean for random, 0-255 for specific), added options object API
    • randomString: Added secure option for cryptographically secure random generation using crypto.getRandomValues()
  • New IE11 Compatibility Functions:

    • arrayFrom: IE11-compatible Array.from()
    • repeatString: IE11-compatible String.prototype.repeat()
  • IE11 Compatibility: Built-in support without external polyfills

    • New hasOwn() compatibility method for Object.hasOwn()
  • 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

Choose a tag to compare

@saqqdy saqqdy released this 15 Mar 02:58

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 @example tags
  • 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

Choose a tag to compare

@saqqdy saqqdy released this 17 Jan 01:55
  1. docs work
  2. upgrade all packages

What's Changed

Full Changelog: 5.23.0...5.23.1

v5.23.0

Choose a tag to compare

@saqqdy saqqdy released this 18 Nov 00:48
  1. punctualTimer got returns of PunctualTimerReturns

Full Changelog: 5.22.1...5.23.0

v5.22.1

Choose a tag to compare

@saqqdy saqqdy released this 15 Nov 11:15
  1. fix bugs of nextVersion

Full Changelog: 5.22.0...5.22.1

v5.22.0

Choose a tag to compare

@saqqdy saqqdy released this 16 Oct 02:13
  1. new isNumberBrowser function, see: isNumberBrowser
  2. Default value of agent string for getOsVersion and getAppVersion changed to navigator.appVersion.

Full Changelog: 5.21.2...5.22.0

v5.21.2

Choose a tag to compare

@saqqdy saqqdy released this 27 Aug 06:02
  1. pattern support 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

Choose a tag to compare

@saqqdy saqqdy released this 12 Aug 10:07
  1. osVersion support Harmony

Full Changelog: 5.21.0...5.21.1

v5.21.0

Choose a tag to compare

@saqqdy saqqdy released this 09 Aug 08:50
  1. spliceUrlParam Breaking change: SpliceUrlParamOptions

Full Changelog: 5.20.0...5.21.0

v5.20.0

Choose a tag to compare

@saqqdy saqqdy released this 09 Aug 07:57
  1. spliceUrlParam Breaking change: remove encodeURIComponent