Package detail

auto-parser

taabish5MIT2.1.0

A flexible parser for dynamic data types (stringified data, numbers, JSON, etc.)

parser, data, stringify, json

readme

AutoParser

npm version Build Status

A flexible parser that automatically converts stringified data types (like integers, floats, arrays, or JSON) back to their original form. Perfect for low-code/no-code environments where values are often passed as strings but need to be parsed correctly on the backend.

Installation

To install the package via npm:

```bash npm install auto-parser

  • Features Automatic Parsing: Detects and converts stringified numbers, arrays, objects, booleans, etc., to their appropriate types. Flexible: Supports a wide variety of data types (number, boolean, stringified JSON objects, etc.). Low-Code Friendly: Useful for scenarios like working with low-code/no-code platforms where values are received as strings. Customizable: Easily extend the parser to handle additional cases as needed.

Usage Once installed, you can use AutoParser to easily parse stringified values into their correct data types:

Example:

const AutoParser = require('auto-parser');

// Initialize the AutoParser const parser = new AutoParser();

// Example 1: Parse a number string let num = parser.parse("123"); // 123 as an integer console.log(num); // 123 (number)

// Example 2: Parse a boolean string let bool = parser.parse("true"); // true as a boolean console.log(bool); // true (boolean)

// Example 3: Parse an array string let arr = parser.parse("[1,2,3]"); // [1, 2, 3] as an array console.log(arr); // [1, 2, 3] (array)

// Example 4: Parse a JSON string let obj = parser.parse('{"name":"John","age":30}'); // Object { name: 'John', age: 30 } console.log(obj); // { name: 'John', age: 30 } (object)

Supported Types: Number: "123" → 123 Boolean: "true" → true, "false" → false Array: "[1, 2, 3]" → [1, 2, 3] Object: '{"key":"value"}' → { key: 'value' } Null: "null" → null Date: "2021-07-01T00:00:00Z" → Date object API AutoParser.parse(input: string) -> any input: A string that can represent a number, boolean, array, object, or date. Returns: The parsed value as the appropriate data type (number, boolean, array, object, date, etc.). Example:

js Copy code let result = parser.parse("123"); // Returns number 123 let result = parser.parse("[1,2,3]"); // Returns array [1, 2, 3]

Supported Types: Number: "123" → 123 Boolean: "true" → true, "false" → false Array: "[1, 2, 3]" → [1, 2, 3] Object: '{"key":"value"}' → { key: 'value' } Null: "null" → null Date: "2021-07-01T00:00:00Z" → Date object API AutoParser.parse(input: string) -> any input: A string that can represent a number, boolean, array, object, or date. Returns: The parsed value as the appropriate data type (number, boolean, array, object, date, etc.). Example:

let result = parser.parse("123"); // Returns number 123 let result = parser.parse("[1,2,3]"); // Returns array [1, 2, 3]

Installation Notes This package is lightweight (around 8KB) and has no external dependencies, making it a great choice for performance-sensitive projects. If you encounter any issues or need additional parsing functionality, feel free to extend the parser using custom logic. Contributing We welcome contributions! If you'd like to help improve the package:

Fork the repository Create a feature branch (git checkout -b feature/your-feature) Commit your changes (git commit -am 'Add new feature') Push to the branch (git push origin feature/your-feature) Open a pull request License MIT License. See the LICENSE file for details.

Changelog v1.1.0 Added support for Date parsing. v1.0.0 Initial release with support for numbers, booleans, arrays, and objects.