ToolPouch

Data

Format and transform data: JSON, CSV, XML, SQL, and query strings.

Install the SDK

npm install @toolpouch/sdkView on npm →

Import from this module

import { functionName } from '@toolpouch/sdk/data'

formatJSON

Signature

formatJSON(json: string, indent?: number): string

Pretty-print and format JSON with specified indentation.

Example

import { formatJSON } from '@toolpouch/sdk/data';
const formatted = formatJSON('{"name":"test"}', 2);
// '{"n": "test"}'

Returns

Formatted JSON string

minifyJSON

Signature

minifyJSON(json: string): string

Minify JSON by removing whitespace.

Example

import { minifyJSON } from '@toolpouch/sdk/data';
const minified = minifyJSON('{ "name": "test" }');
// '{"name":"test"}'

Returns

Minified JSON string

validateJSON

Signature

validateJSON(json: string): { valid: boolean; error?: string }

Validate if a string is valid JSON.

Example

import { validateJSON } from '@toolpouch/sdk/data';
const result = validateJSON('{"valid":true}');
// { valid: true }

Returns

Object with valid boolean and optional error message

jsonToYaml

Signature

jsonToYaml(json: string): string

Convert JSON to YAML format.

Example

import { jsonToYaml } from '@toolpouch/sdk/data';
const yaml = jsonToYaml('{"name":"test"}');
// 'name: test'

Returns

YAML formatted string

csvToJson

Signature

csvToJson(csv: string): Record<string, string>[]

Convert CSV to an array of JSON objects.

Example

import { csvToJson } from '@toolpouch/sdk/data';
const json = csvToJson('name,age\nAlice,30');
// [{name:'Alice',age:'30'}]

Returns

Array of objects

jsonToCsv

Signature

jsonToCsv(json: string): string

Convert JSON array to CSV format.

Example

import { jsonToCsv } from '@toolpouch/sdk/data';
const csv = jsonToCsv('[{"name":"Alice","age":30}]');
// 'name,age\nAlice,30'

Returns

CSV formatted string

formatXml

Signature

formatXml(xml: string, indent?: number): string

Pretty-print and format XML with specified indentation.

Example

import { formatXml } from '@toolpouch/sdk/data';
const formatted = formatXml('text');
// '\n  \n    text\n  \n'

Returns

Formatted XML string

formatSql

Signature

formatSql(sql: string): string

Format SQL query with proper line breaks and indentation.

Example

import { formatSql } from '@toolpouch/sdk/data';
const sql = formatSql('SELECT * FROM users WHERE age > 18');
// 'SELECT\n*\nFROM\nusers\nWHERE\nage > 18'

Returns

Formatted SQL string

parseQueryString

Signature

parseQueryString(qs: string): Record<string, string>

Parse URL query string into an object.

Example

import { parseQueryString } from '@toolpouch/sdk/data';
const params = parseQueryString('?name=test&id=123');
// { name: 'test', id: '123' }

Returns

Object with query parameters

buildQueryString

Signature

buildQueryString(params: Record<string, string>): string

Build URL query string from an object.

Example

import { buildQueryString } from '@toolpouch/sdk/data';
const qs = buildQueryString({name:'test',id:'123'});
// 'name=test&id=123'

Returns

URL query string