
Research
/Security News
Miasma Mini Shai-Hulud Hits ImmobiliareLabs npm Packages
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.
@hyperfrontend/string-utils
Advanced tools
Isomorphic string encoding utilities with unified APIs for browser and Node.js environments.
Isomorphic string encoding utilities with unified APIs for browser and Node.js environments.
@hyperfrontend/string-utils provides a consistent, cross-platform API for encoding operations that typically differ between browser and Node.js environments. The library specializes in UTF-8 and base64 conversions, offering identical function signatures across platforms while optimizing each implementation for its native environment.
Rather than wrapping platform differences behind abstraction layers, the library exposes platform-specific entry points (/browser and /node) that deliver optimal performance by leveraging TextEncoder/atob/btoa in browsers and Buffer in Node.js. This design eliminates runtime environment detection overhead while ensuring tree-shaking efficiency.
The library maintains separate browser and Node.js implementations that share identical APIs but optimize for platform-specific capabilities. Browser implementations use TextEncoder/TextDecoder and atob/btoa, while Node.js implementations leverage Buffer operations. This dual-implementation strategy avoids runtime checks and polyfills, resulting in smaller bundles and better performance.
String encoding operations differ significantly between browsers and Node.js. Browser APIs like btoa() don't handle UTF-8 correctly, and Node.js lacks native base64-to-Uint8Array converters. This library provides consistent APIs that "just work" across platforms while handling edge cases like multi-byte UTF-8 characters and binary string conversions.
Example pain point solved: btoa('こんにちは') throws in browsers because it expects Latin-1 encoding, but toBase64('こんにちは') correctly handles UTF-8 encoding in both environments.
All cryptographic operations in @hyperfrontend/cryptography depend on these encoding utilities for converting between text strings and binary data. The library provides the UTF-8 ↔ Uint8Array conversions essential for encryption/decryption workflows, ensuring consistent encoding behavior across Web Crypto API (browser) and Node.js crypto implementations.
Many APIs (JWTs, URL query parameters, cloud storage identifiers) require URL-safe base64 encoding where + becomes - and / becomes _, with padding characters optionally removed. This library handles these transformations automatically with simple boolean flags, eliminating error-prone manual string replacements.
String manipulation with regular expressions can expose applications to ReDoS (Regular Expression Denial of Service) attacks. This library explicitly avoids regex operations for padding removal and character replacements, using loop-based approaches that guarantee linear time complexity regardless of input patterns.
By exposing separate /browser and /node entry points rather than auto-detecting environments at runtime, the library enables bundlers to eliminate unused code automatically. Frontend builds only include browser implementations, and backend builds only include Node.js implementations—no dead code, no runtime checks.
npm install @hyperfrontend/string-utils
Browser usage:
import { toBase64, fromBase64, utf8StringToUint8Array } from '@hyperfrontend/string-utils/browser'
// Standard base64 encoding
const encoded = toBase64('Hello, World!')
console.log(encoded) // 'SGVsbG8sIFdvcmxkIQ=='
// URL-safe base64 without padding
const urlSafe = toBase64('Hello, World!', true, false)
console.log(urlSafe) // 'SGVsbG8sIFdvcmxkIQ' (no padding)
// Decoding (handles both standard and URL-safe)
const decoded = fromBase64(urlSafe)
console.log(decoded) // 'Hello, World!'
// UTF-8 to binary for crypto operations
const bytes = utf8StringToUint8Array('こんにちは')
console.log(bytes) // Uint8Array[227, 129, 147, ...]
Node.js usage:
import { toBase64, fromBase64, utf8StringToUint8Array } from '@hyperfrontend/string-utils/node'
// Identical API, optimized Node.js implementation
const encoded = toBase64('Hello, World!')
const bytes = utf8StringToUint8Array('こんにちは')
All functions are available from both /browser and /node entry points with identical signatures:
toBase64(text, urlSafe?, keepPadding?) - Encode UTF-8 string to base64fromBase64(base64) - Decode base64 string to UTF-8 (supports standard and URL-safe)utf8StringToUint8Array(text) - Convert UTF-8 string to Uint8Arrayuint8ArrayToUtf8String(bytes) - Convert Uint8Array to UTF-8 stringarrayBufferToUtf8String(buffer) - Convert ArrayBuffer to UTF-8 stringuint8ArrayToBase64(bytes, urlSafe?, keepPadding?) - Encode Uint8Array to base64base64ToUint8Array(base64) - Decode base64 string to Uint8ArrayInternal utilities (exported but typically not needed):
bytesToBinaryString(bytes) - Uint8Array to Latin-1 binary string (for browser btoa interop)binaryStringToBytes(binaryStr) - Latin-1 binary string to Uint8Array (for browser atob interop)base64ToUrlSafeBase64(base64, options) - Transform standard base64 to URL-safe formaturlSafeBase64ToBase64(urlSafeBase64) - Transform URL-safe base64 to standard format| Platform | Support |
|---|---|
| Browser | ✅ |
| Node.js | ✅ |
| Web Workers | ✅ |
| Deno, Bun, Cloudflare Workers | ✅ |
| Format | File | Tree-Shakeable |
|---|---|---|
| ESM | index.esm.js | ✅ |
| CJS | index.cjs.js | ❌ |
| IIFE | bundle/index.iife.min.js | ❌ |
| UMD | bundle/index.umd.min.js | ❌ |
<!-- unpkg -->
<script src="https://unpkg.com/@hyperfrontend/string-utils"></script>
<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/@hyperfrontend/string-utils"></script>
<script>
const { utf8StringToUint8Array, uint8ArrayToBase64 } = HyperfrontendStringUtils
</script>
Global variable: HyperfrontendStringUtils
None — zero external dependencies.
This library is part of the hyperfrontend monorepo.
MIT
FAQs
Isomorphic string encoding utilities with unified APIs for browser and Node.js environments.
The npm package @hyperfrontend/string-utils receives a total of 154 weekly downloads. As such, @hyperfrontend/string-utils popularity was classified as not popular.
We found that @hyperfrontend/string-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.

Security News
Rolldown paused Rust React Compiler integration after a 5MB binary size increase raised concerns about shipping React-specific code to all Vite users.

Security News
/Research
Mini Shai-Hulud expands into the Go ecosystem after hitting LeoPlatform npm packages and targeting GitHub Actions workflows.