strfy-js
Stringify JSON as JavaScript 🌴
strfy-js is a custom JavaScript serialization library designed to extend the capabilities of JSON serialization. This library is particularly useful for generating JavaScript objects directly from JSON, enabling developers to work with JSON data more effectively within JavaScript environments.
Features
-
🛠️ Extended Serialization: Converts JSON to JavaScript objects, supporting output, such as properties without quotes, not typically handled by standard JSON.
-
⚙️ Customizable: Offers various options to customize the output, making it suitable for different use cases. Tailor the serialization process to meet your specific requirements.
-
⚡ Lightweight and Fast: Optimized for performance, making it a practical choice for applications that require fast serialization of large amounts of data. Ideal for handling high-load environments efficiently.
Installation
To install strfy-js, use npm or yarn:
npm install strfy-js
yarn add strfy-js
Usage
Import jsStringify from strfy-js and use it to serialize JavaScript objects:
import { jsStringify } from 'strfy-js';
const obj = {
"$schema": "schema.json",
"chain_id": "cosmos-1",
"logo_URIs": {
"png": "cosmos.png"
},
"binaries": {
"linux/amd64": "cosmos-bin.tar.gz"
}
};
const options = {
space: 2,
camelCase: true,
quotes: 'single'
};
console.log(jsStringify(obj, options));
{
$schema: 'schema.json',
chainId: 'cosmos-1',
logoURIs: {
png: 'cosmos.png'
},
binaries: {
"linux/amd64": 'cosmos-bin.tar.gz'
}
}
Options
jsStringify accepts the following options in the StringifyOptions interface:
space (optional): Specifies the number of spaces to use for indentation, defaults to 0.
replacer (optional): A function that alters the behavior of the stringification process by filtering and transforming the values.
quotes (optional): Determines the type of quotes around strings. Can be 'single', 'double', or determined automatically to avoid escapes.
inlineArrayLimit (optional): Allows arrays to be serialized inline if they have fewer elements than the specified limit.
camelCase (optional): When set to true, object keys are transformed into camelCase.
camelCaseFn (optional): A custom function that can be provided to convert object keys into camelCase using a custom transformation logic.
Development
Setup
git clone https://github.com/constructive-io/dev-utils.git
cd dev-utils
pnpm install
pnpm build
- Test the package of interest:
cd packages/<packagename>
pnpm test:watch
Credits
🛠 Built by the Constructive team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on GitHub.
Disclaimer
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.