@cloudwerk/utils
v0.6.1
Published
Shared browser-safe utilities for Cloudwerk
Downloads
37
Readme
@cloudwerk/utils
Browser-safe utilities for Cloudwerk. Zero dependencies, works in both server and browser environments.
Installation
npm install @cloudwerk/utilsExports
import {
serializeProps,
deserializeProps,
escapeHtmlAttribute
} from '@cloudwerk/utils'API
serializeProps(props: unknown): string
Serialize props to a JSON string for embedding in HTML attributes.
const serialized = serializeProps({ user: { name: 'Alice' } })
// '{"user":{"name":"Alice"}}'deserializeProps<T>(value: string): T
Deserialize props from a JSON string.
const props = deserializeProps<{ user: { name: string } }>(serialized)
// { user: { name: 'Alice' } }escapeHtmlAttribute(value: string): string
Escape a string for safe use in HTML attributes.
const safe = escapeHtmlAttribute('Hello "World"')
// 'Hello "World"'Use Case
These utilities are primarily used internally by @cloudwerk/ui for client component hydration, but are available for direct use when building custom rendering solutions.
Documentation
For full documentation, visit: https://github.com/squirrelsoft-dev/cloudwerk
Part of Cloudwerk
This package is part of the Cloudwerk monorepo.
