### Install picoquery Source: https://github.com/43081j/picoquery/blob/main/README.md Install picoquery using npm. Ensure your Node.js version supports ESM or use version 1.x for CommonJS compatibility. ```sh npm i -S picoquery ``` -------------------------------- ### Default options for picoquery Source: https://github.com/43081j/picoquery/blob/main/README.md View the default configuration options for `parse` and `stringify`. These include settings for nesting, array handling, delimiters, and more. ```ts { nesting: true, nestingSyntax: 'dot', arrayRepeat: false, arrayRepeatSyntax: 'repeat', delimiter: '&' } ``` -------------------------------- ### Options Interface Source: https://context7.com/43081j/picoquery/llms.txt The complete options interface for configuring both `parse` and `stringify` behavior in Picoquery. ```APIDOC ## Options Interface ### Description The complete options interface for configuring both `parse` and `stringify` behavior. ### Interface Definition ```typescript import type { Options, ParseOptions, StringifyOptions } from 'picoquery'; // Full options interface const fullOptions: Partial = { // Enable/disable nested object parsing (default: true) nesting: true, // Nesting syntax: 'dot' | 'index' | 'js' (default: 'dot') nestingSyntax: 'dot', // Treat repeated keys as arrays (default: false) arrayRepeat: false, // Array syntax: 'repeat' | 'bracket' (default: 'repeat') arrayRepeatSyntax: 'repeat', // Key-value pair delimiter (default: '&' or 38) delimiter: '&', // Custom value deserializer for parsing valueDeserializer: (value, key) => value, // Custom key deserializer for parsing keyDeserializer: (key) => key, // Custom value serializer for stringifying valueSerializer: (value, key) => String(value), // Function to check if object should be serialized directly shouldSerializeObject: (value) => value instanceof Date }; // ParseOptions is Partial const parseOpts: ParseOptions = { nesting: true, nestingSyntax: 'index', arrayRepeat: true }; // StringifyOptions is Partial const stringifyOpts: StringifyOptions = { nestingSyntax: 'js', delimiter: ';' }; ``` ``` -------------------------------- ### Picoquery - Parse with arrayRepeat Option Source: https://context7.com/43081j/picoquery/llms.txt Explains how to use the `arrayRepeat` and `arrayRepeatSyntax` options to handle repeated keys as arrays during query string parsing. ```APIDOC ## parse with arrayRepeat option Enables treating repeated keys as arrays. Combined with `arrayRepeatSyntax`, supports both `repeat` style (`foo=x&foo=y`) and `bracket` style (`foo[]=x&foo[]=y`). ### Method GET (conceptually, as it operates on a string) ### Endpoint N/A (This is a function within the library) ### Parameters #### Query Parameters - **queryString** (string) - Required - The query string to parse. - **options** (object) - Required - Configuration options for parsing. - **arrayRepeat** (boolean) - Required - Enables treating repeated keys as arrays. - **arrayRepeatSyntax** (string) - Optional - Specifies the syntax for repeated arrays. Options: 'repeat', 'bracket'. Defaults to 'repeat'. - **nesting** (boolean) - Optional - Enables or disables nesting. Defaults to true. - **nestingSyntax** (string) - Optional - Specifies the nesting syntax ('dot', 'index', 'js'). Defaults to 'dot'. ### Request Example ```javascript import { parse } from 'picoquery'; // Repeated keys become arrays with arrayRepeat enabled const repeated = parse('foo=x&foo=y&foo=z', { arrayRepeat: true, arrayRepeatSyntax: 'repeat' }); // Result: { foo: ['x', 'y', 'z'] } // Single value stays as string const singleValue = parse('foo=x', { arrayRepeat: true, arrayRepeatSyntax: 'repeat' }); // Result: { foo: 'x' } // Bracket syntax for arrays: foo[]=value const bracketArray = parse('foo[]=x&foo[]=y', { arrayRepeat: true, arrayRepeatSyntax: 'bracket' }); // Result: { foo: ['x', 'y'] } // Combine with nesting for nested arrays const nestedRepeated = parse('foo.bar=x&foo.bar=y', { arrayRepeat: true, arrayRepeatSyntax: 'repeat' }); // Result: { foo: { bar: ['x', 'y'] } } // Bracket arrays with index nesting syntax const indexBracket = parse('foo[bar][]=x&foo[bar][]=y', { nesting: true, nestingSyntax: 'index', arrayRepeat: true, arrayRepeatSyntax: 'bracket' }); // Result: { foo: { bar: ['x', 'y'] } } ``` ### Response #### Success Response (200) - **parsedObject** (object) - The JavaScript object representation of the query string. #### Response Example ```json { "foo": [ "x", "y", "z" ] } ``` ``` -------------------------------- ### stringify Configuration Options Source: https://context7.com/43081j/picoquery/llms.txt Endpoints and configuration options for the stringify function, including nesting syntax, array repetition, and custom value serialization. ```APIDOC ## stringify(object, options) ### Description Converts a JavaScript object into a query string based on provided configuration options. ### Parameters #### Request Body - **object** (Object) - Required - The source object to serialize. - **options** (Object) - Optional - Configuration object: - **nestingSyntax** (string) - 'index' (bracket notation) or 'js' (dot/bracket notation). - **nesting** (boolean) - Whether to enable nested object serialization. - **arrayRepeat** (boolean) - Whether to use repeated keys for arrays. - **arrayRepeatSyntax** (string) - 'repeat' (key=val&key=val) or 'bracket' (key[]=val&key[]=val). - **valueSerializer** (function) - Custom function to transform values. - **shouldSerializeObject** (function) - Predicate to determine if an object should be serialized. - **delimiter** (string) - Character used to separate key-value pairs (default '&'). ### Response - **string** - The resulting query string. ``` ```APIDOC ## defaultValueSerializer(value, key) ### Description The default utility function used by stringify to handle standard JavaScript types (strings, numbers, booleans, BigInt, Date). ### Parameters - **value** (any) - The value to serialize. - **key** (string) - The key associated with the value. ### Response - **string** - The URL-encoded string representation of the value. ``` -------------------------------- ### parse(str[, options]) Source: https://github.com/43081j/picoquery/blob/main/README.md Parses a query string into a JavaScript object based on provided configuration options. ```APIDOC ## parse(str[, options]) ### Description Parses the given query string into an object, optionally with configured options. ### Parameters #### Path Parameters - **str** (string) - Required - The query string to parse. #### Request Body - **options** (object) - Optional - Configuration object including nesting, arrayRepeat, delimiter, valueDeserializer, and keyDeserializer settings. ### Response #### Success Response (200) - **object** (object) - The parsed query string object. ``` -------------------------------- ### Picoquery - Parse with nestingSyntax Option Source: https://context7.com/43081j/picoquery/llms.txt Demonstrates how to configure the `nestingSyntax` option for the `parse` function to control how nested objects and arrays are interpreted. ```APIDOC ## parse with nestingSyntax option Configures the nesting syntax used for parsing nested objects and arrays. Options include `dot` (default), `index` (bracket notation), and `js` (JavaScript-style with dots for properties and brackets for array indices). ### Method GET (conceptually, as it operates on a string) ### Endpoint N/A (This is a function within the library) ### Parameters #### Query Parameters - **queryString** (string) - Required - The query string to parse. - **options** (object) - Required - Configuration options for parsing. - **nestingSyntax** (string) - Required - Specifies the nesting syntax. Options: 'dot', 'index', 'js'. ### Request Example ```javascript import { parse } from 'picoquery'; // Index/bracket syntax: foo[bar]=value const indexSyntax = parse('foo[bar]=x&foo[baz]=y', { nestingSyntax: 'index' }); // Result: { foo: { bar: 'x', baz: 'y' } } // Array indexing with bracket syntax const arrayIndex = parse('foo[0]=first&foo[1]=second', { nestingSyntax: 'index' }); // Result: { foo: ['first', 'second'] } // Deep nesting with bracket syntax const deepBracket = parse('user[address][city]=NYC', { nestingSyntax: 'index' }); // Result: { user: { address: { city: 'NYC' } } } // JavaScript-style: dots for properties, brackets for array indices const jsSyntax = parse('foo.bar[0]=x&foo.bar[1]=y', { nestingSyntax: 'js' }); // Result: { foo: { bar: ['x', 'y'] } } // Complex JS-style nesting with objects inside arrays const complexJs = parse('foo.bar[0].baz=value', { nestingSyntax: 'js' }); // Result: { foo: { bar: [{ baz: 'value' }] } } // Disable nesting entirely const noNesting = parse('foo.bar=x', { nesting: false }); // Result: { 'foo.bar': 'x' } ``` ### Response #### Success Response (200) - **parsedObject** (object) - The JavaScript object representation of the query string. #### Response Example ```json { "foo": { "bar": "x", "baz": "y" } } ``` ``` -------------------------------- ### stringify(object[, options]) Source: https://github.com/43081j/picoquery/blob/main/README.md Converts a JavaScript object into a query string based on provided configuration options. ```APIDOC ## stringify(object[, options]) ### Description Converts the given object into a query string, optionally with configured options. ### Parameters #### Path Parameters - **object** (object) - Required - The object to convert into a query string. #### Request Body - **options** (object) - Optional - Configuration object including nesting, nestingSyntax, arrayRepeat, arrayRepeatSyntax, delimiter, and shouldSerializeObject settings. ### Response #### Success Response (200) - **string** (string) - The resulting query string. ``` -------------------------------- ### Define Parse and Stringify Options Source: https://context7.com/43081j/picoquery/llms.txt Configures the behavior of query string parsing and stringification, including nesting syntax, delimiters, and custom serializers. ```typescript import type { Options, ParseOptions, StringifyOptions } from 'picoquery'; // Full options interface const fullOptions: Partial = { // Enable/disable nested object parsing (default: true) nesting: true, // Nesting syntax: 'dot' | 'index' | 'js' (default: 'dot') nestingSyntax: 'dot', // Treat repeated keys as arrays (default: false) arrayRepeat: false, // Array syntax: 'repeat' | 'bracket' (default: 'repeat') arrayRepeatSyntax: 'repeat', // Key-value pair delimiter (default: '&' or 38) delimiter: '&', // Custom value deserializer for parsing valueDeserializer: (value, key) => value, // Custom key deserializer for parsing keyDeserializer: (key) => key, // Custom value serializer for stringifying valueSerializer: (value, key) => String(value), // Function to check if object should be serialized directly shouldSerializeObject: (value) => value instanceof Date }; // ParseOptions is Partial const parseOpts: ParseOptions = { nesting: true, nestingSyntax: 'index', arrayRepeat: true }; // StringifyOptions is Partial const stringifyOpts: StringifyOptions = { nestingSyntax: 'js', delimiter: ';' }; ``` -------------------------------- ### Parse query strings with default options Source: https://context7.com/43081j/picoquery/llms.txt Uses dot syntax for nesting and the & delimiter by default. Automatically handles URL decoding and plus-sign-to-space conversion. ```typescript import { parse } from 'picoquery'; // Basic parsing with default options (dot nesting syntax) const basic = parse('foo=x&bar=y'); // Result: { foo: 'x', bar: 'y' } // Nested objects with dot syntax (default) const nested = parse('foo.bar=abc&baz=def'); // Result: { foo: { bar: 'abc' }, baz: 'def' } // Nested arrays with dot syntax const nestedArray = parse('foo.0=first&foo.1=second'); // Result: { foo: ['first', 'second'] } // Deep nesting const deepNested = parse('user.address.city=NYC&user.address.zip=10001'); // Result: { user: { address: { city: 'NYC', zip: '10001' } } } // URL-encoded keys and values are automatically decoded const encoded = parse('foo%20bar=baz%20qux'); // Result: { 'foo bar': 'baz qux' } // Plus signs are decoded as spaces const plusEncoded = parse('foo+bar=hello+world'); // Result: { 'foo bar': 'hello world' } // Empty values const emptyValues = parse('foo&bar'); // Result: { foo: '', bar: '' } ``` -------------------------------- ### Support arrays with nesting Source: https://github.com/43081j/picoquery/blob/main/README.md When `nesting` is enabled, `parse` and `stringify` can handle arrays using index notation. ```ts parse('foo.0=bar', {nesting: true}); // {foo: ['bar']} stringify({foo: ['bar']}, {nesting: true}); // foo.0=bar ``` -------------------------------- ### stringify(object, options) Source: https://github.com/43081j/picoquery/blob/main/README.md The stringify function converts an object into a query string. The valueSerializer option allows for custom serialization logic for specific values. ```APIDOC ## stringify(object, options) ### Description Converts a JavaScript object into a query string. Supports custom serialization via the `valueSerializer` option. ### Parameters #### Request Body - **object** (object) - Required - The object to be stringified. - **options** (object) - Optional - Configuration options. - **valueSerializer** (function) - Optional - A function called with `(value: unknown, key: PropertyKey) => string` to serialize values. ### Request Example ```ts stringify({foo: 'bar'}, { valueSerializer: (val) => String(val) + String(val) }); ``` ### Response - **string** - The resulting query string. ``` -------------------------------- ### Stringify with Nesting Syntax Option Source: https://context7.com/43081j/picoquery/llms.txt Configure how nested objects and arrays are represented in the query string. Use 'index' for bracket notation or 'js' for dot notation with brackets for arrays. Nesting can be disabled entirely. ```typescript import { stringify } from 'picoquery'; // Index/bracket syntax const indexSyntax = stringify( { foo: { bar: 'x', baz: 'y' } }, { nestingSyntax: 'index' } ); // Result: 'foo[bar]=x&foo[baz]=y' // Arrays with index syntax const arrayIndex = stringify( { items: ['a', 'b', 'c'] }, { nestingSyntax: 'index' } ); // Result: 'items[0]=a&items[1]=b&items[2]=c' // JavaScript-style (dots for objects, brackets for arrays) const jsSyntax = stringify( { foo: { bar: ['x', 'y'] } }, { nestingSyntax: 'js' } ); // Result: 'foo.bar[0]=x&foo.bar[1]=y' // Complex nested structure with JS syntax const complexJs = stringify( { users: [{ name: 'John' }, { name: 'Jane' }] }, { nestingSyntax: 'js' } ); // Result: 'users[0].name=John&users[1].name=Jane' // Disable nesting const noNesting = stringify( { foo: { bar: 'x' } }, { nesting: false } ); // Result: '' (nested objects ignored when nesting is disabled) ``` -------------------------------- ### Handle repeated keys as arrays Source: https://github.com/43081j/picoquery/blob/main/README.md Set `arrayRepeat` to `true` to treat multiple keys with the same name as an array. ```ts parse('foo=x&foo=y', {arrayRepeat: true}); // {foo: ['x', 'y']} stringify({foo: ['x', 'y']}, {arrayRepeat: true}); // foo=x&foo=y ``` -------------------------------- ### Enable nesting with stringify Source: https://github.com/43081j/picoquery/blob/main/README.md When `nesting` is true, `stringify` supports nested objects using dot notation. ```ts stringify({foo: {bar: 'baz'}}, {nesting: true}); // foo.bar=baz ``` -------------------------------- ### Use a custom delimiter Source: https://github.com/43081j/picoquery/blob/main/README.md Specify a custom `delimiter` option for parsing and stringifying query strings. ```ts parse('foo=x;bar=y', {delimiter: ';'}); // {foo: 'x', bar: 'y'} stringify({foo: 'x', bar: 'y'}, {delimiter: ';'}); // foo=x;bar=y ``` -------------------------------- ### Fallback to default serialization logic Source: https://github.com/43081j/picoquery/blob/main/README.md Import `defaultShouldSerializeObject` to combine custom logic with the library's default behavior for `shouldSerializeObject`. ```ts import {defaultShouldSerializeObject, stringify} from 'picoquery'; stringify({ foo: new StringifiableObject('test') }, { shouldSerializeObject(val) { if (val instanceof StringifableObject) { return true; } return defaultShouldSerializeObject(val); } }); ``` -------------------------------- ### Parse query strings with array repetition Source: https://context7.com/43081j/picoquery/llms.txt Enables array creation from repeated keys using arrayRepeat and arrayRepeatSyntax options. Supports both 'repeat' and 'bracket' styles. ```typescript import { parse } from 'picoquery'; // Repeated keys become arrays with arrayRepeat enabled const repeated = parse('foo=x&foo=y&foo=z', { arrayRepeat: true, arrayRepeatSyntax: 'repeat' }); // Result: { foo: ['x', 'y', 'z'] } // Single value stays as string const singleValue = parse('foo=x', { arrayRepeat: true, arrayRepeatSyntax: 'repeat' }); // Result: { foo: 'x' } // Bracket syntax for arrays: foo[]=value const bracketArray = parse('foo[]=x&foo[]=y', { arrayRepeat: true, arrayRepeatSyntax: 'bracket' }); // Result: { foo: ['x', 'y'] } // Combine with nesting for nested arrays const nestedRepeated = parse('foo.bar=x&foo.bar=y', { arrayRepeat: true, arrayRepeatSyntax: 'repeat' }); // Result: { foo: { bar: ['x', 'y'] } } // Bracket arrays with index nesting syntax const indexBracket = parse('foo[bar][]=x&foo[bar][]=y', { nesting: true, nestingSyntax: 'index', arrayRepeat: true, arrayRepeatSyntax: 'bracket' }); // Result: { foo: { bar: ['x', 'y'] } } ``` -------------------------------- ### Deserialize keys with a custom function Source: https://github.com/43081j/picoquery/blob/main/README.md Provide a `keyDeserializer` function to transform keys during parsing. The function receives the raw key string. ```ts parse('300=foo', { keyDeserializer: (key) => { const asNum = Number(key); return Number.isNaN(asNum) ? key : asNum; } }); // {300: 'foo'} ``` -------------------------------- ### Stringify with Array Repeat Option Source: https://context7.com/43081j/picoquery/llms.txt Control how arrays are serialized. 'repeat' uses repeated keys, while 'bracket' uses indexed brackets. This can be combined with nesting. ```typescript import { stringify } from 'picoquery'; // Repeat syntax: foo=x&foo=y const repeatSyntax = stringify( { tags: ['javascript', 'typescript'] }, { arrayRepeat: true, arrayRepeatSyntax: 'repeat' } ); // Result: 'tags=javascript&tags=typescript' // Bracket syntax: foo[]=x&foo[]=y const bracketSyntax = stringify( { tags: ['javascript', 'typescript'] }, { arrayRepeat: true, arrayRepeatSyntax: 'bracket' } ); // Result: 'tags[]=javascript&tags[]=typescript' // Combined with nesting const nestedArray = stringify( { user: { roles: ['admin', 'editor'] } }, { arrayRepeat: true, arrayRepeatSyntax: 'repeat' } ); // Result: 'user.roles=admin&user.roles=editor' // Bracket arrays with index nesting const indexBracket = stringify( { foo: { bar: ['x', 'y'] } }, { nestingSyntax: 'index', arrayRepeat: true, arrayRepeatSyntax: 'bracket' } ); // Result: 'foo[bar][]=x&foo[bar][]=y' ``` -------------------------------- ### Parse query strings with custom nesting syntax Source: https://context7.com/43081j/picoquery/llms.txt Configures how nested objects and arrays are parsed using the nestingSyntax option. Supports 'dot', 'index', and 'js' styles. ```typescript import { parse } from 'picoquery'; // Index/bracket syntax: foo[bar]=value const indexSyntax = parse('foo[bar]=x&foo[baz]=y', { nestingSyntax: 'index' }); // Result: { foo: { bar: 'x', baz: 'y' } } // Array indexing with bracket syntax const arrayIndex = parse('foo[0]=first&foo[1]=second', { nestingSyntax: 'index' }); // Result: { foo: ['first', 'second'] } // Deep nesting with bracket syntax const deepBracket = parse('user[address][city]=NYC', { nestingSyntax: 'index' }); // Result: { user: { address: { city: 'NYC' } } } // JavaScript-style: dots for properties, brackets for array indices const jsSyntax = parse('foo.bar[0]=x&foo.bar[1]=y', { nestingSyntax: 'js' }); // Result: { foo: { bar: ['x', 'y'] } } // Complex JS-style nesting with objects inside arrays const complexJs = parse('foo.bar[0].baz=value', { nestingSyntax: 'js' }); // Result: { foo: { bar: [{ baz: 'value' }] } } // Disable nesting entirely const noNesting = parse('foo.bar=x', { nesting: false }); // Result: { 'foo.bar': 'x' } ``` -------------------------------- ### Enable nesting with parse Source: https://github.com/43081j/picoquery/blob/main/README.md When `nesting` is true, `parse` supports nested objects using dot notation. ```ts parse('foo.bar=baz', {nesting: true}); // {foo: {bar: 'baz'}} ``` -------------------------------- ### Stringify objects in TypeScript Source: https://context7.com/43081j/picoquery/llms.txt Convert JavaScript objects into query strings with support for nesting, arrays, and automatic URL encoding. ```typescript import { stringify } from 'picoquery'; // Basic stringification const basic = stringify({ foo: 'x', bar: 'y' }); // Result: 'foo=x&bar=y' // Nested objects with dot syntax (default) const nested = stringify({ foo: { bar: 'abc' }, baz: 'def' }); // Result: 'foo.bar=abc&baz=def' // Arrays become indexed properties const array = stringify({ foo: ['first', 'second'] }); // Result: 'foo.0=first&foo.1=second' // Deep nesting const deepNested = stringify({ user: { address: { city: 'NYC', zip: '10001' } } }); // Result: 'user.address.city=NYC&user.address.zip=10001' // Special characters are URL-encoded const encoded = stringify({ 'foo bar': 'hello world' }); // Result: 'foo%20bar=hello%20world' // Number values are converted to strings const numbers = stringify({ count: 42, price: 19.99 }); // Result: 'count=42&price=19.99' // Boolean values const booleans = stringify({ enabled: true, disabled: false }); // Result: 'enabled=true&disabled=false' // BigInt values const bigint = stringify({ big: BigInt(12345678901234567890n) }); // Result: 'big=12345678901234567890' // Date values are converted to ISO strings const date = stringify({ created: new Date('2024-01-15') }); // Result: 'created=2024-01-15T00%3A00%3A00.000Z' // Undefined values are skipped const withUndefined = stringify({ foo: undefined, bar: 'baz' }); // Result: 'bar=baz' // Empty arrays are skipped const withEmptyArray = stringify({ foo: [], bar: 'baz' }); // Result: 'bar=baz' // Null input returns empty string const nullInput = stringify(null); // Result: '' ``` -------------------------------- ### Parse with custom deserializers in TypeScript Source: https://context7.com/43081j/picoquery/llms.txt Use keyDeserializer and valueDeserializer to transform keys and values during parsing. Built-in helpers are available for numeric conversions. ```typescript import { parse, numberKeyDeserializer, numberValueDeserializer } from 'picoquery'; // Convert numeric values to numbers const numericValues = parse('count=42&price=19.99', { valueDeserializer: numberValueDeserializer }); // Result: { count: 42, price: 19.99 } // Non-numeric values remain as strings const mixedValues = parse('count=42&name=John', { valueDeserializer: numberValueDeserializer }); // Result: { count: 42, name: 'John' } // Convert numeric keys to numbers const numericKeys = parse('0=first&1=second', { keyDeserializer: numberKeyDeserializer }); // Result: { 0: 'first', 1: 'second' } (keys are actual numbers) // Custom value deserializer for booleans const booleanDeserializer = parse('enabled=true&disabled=false', { valueDeserializer: (value) => { if (value === 'true') return true; if (value === 'false') return false; return value; } }); // Result: { enabled: true, disabled: false } // Custom key deserializer for transforming keys const customKeys = parse('user_name=John&user_age=30', { keyDeserializer: (key) => key.replace('user_', '') }); // Result: { name: 'John', age: '30' } // Parse arrays with numeric values const numericArray = parse('foo.0=1&foo.1=2', { valueDeserializer: numberValueDeserializer }); // Result: { foo: [1, 2] } ``` -------------------------------- ### Picoquery - Parse Function Source: https://context7.com/43081j/picoquery/llms.txt The `parse` function in Picoquery allows you to convert a query string into a JavaScript object. It supports various configurations for nesting, delimiters, and value deserialization. ```APIDOC ## parse Parses a query string into a JavaScript object. Supports nested objects and arrays through configurable nesting syntax, custom delimiters, and value deserialization. By default, uses dot syntax for nesting and the `&` delimiter. ### Method GET (conceptually, as it operates on a string) ### Endpoint N/A (This is a function within the library) ### Parameters #### Query Parameters - **queryString** (string) - Required - The query string to parse. - **options** (object) - Optional - Configuration options for parsing. - **nestingSyntax** (string) - Optional - Specifies the nesting syntax ('dot', 'index', 'js'). Defaults to 'dot'. - **nesting** (boolean) - Optional - Enables or disables nesting. Defaults to true. - **arrayRepeat** (boolean) - Optional - Enables treating repeated keys as arrays. Defaults to false. - **arrayRepeatSyntax** (string) - Optional - Specifies the syntax for repeated arrays ('repeat', 'bracket'). Defaults to 'repeat'. - **delimiter** (string) - Optional - The delimiter used to separate key-value pairs. Defaults to '&'. - **customDeserializers** (object) - Optional - Custom deserializers for keys and values. ### Request Example ```javascript import { parse } from 'picoquery'; // Basic parsing const basic = parse('foo=x&bar=y'); // Result: { foo: 'x', bar: 'y' } // Nested objects with dot syntax const nested = parse('foo.bar=abc&baz=def'); // Result: { foo: { bar: 'abc' }, baz: 'def' } // Nested arrays with dot syntax const nestedArray = parse('foo.0=first&foo.1=second'); // Result: { foo: ['first', 'second'] } // Deep nesting const deepNested = parse('user.address.city=NYC&user.address.zip=10001'); // Result: { user: { address: { city: 'NYC', zip: '10001' } } } // URL-encoded keys and values are automatically decoded const encoded = parse('foo%20bar=baz%20qux'); // Result: { 'foo bar': 'baz qux' } // Plus signs are decoded as spaces const plusEncoded = parse('foo+bar=hello+world'); // Result: { 'foo bar': 'hello world' } // Empty values const emptyValues = parse('foo&bar'); // Result: { foo: '', bar: '' } ``` ### Response #### Success Response (200) - **parsedObject** (object) - The JavaScript object representation of the query string. #### Response Example ```json { "foo": "x", "bar": "y" } ``` ``` -------------------------------- ### Stringify with Custom Delimiter Source: https://context7.com/43081j/picoquery/llms.txt Change the character used to separate key-value pairs in the generated query string. This can be combined with nesting. ```typescript import { stringify } from 'picoquery'; // Semicolon delimiter const semicolonDelim = stringify( { foo: 'x', bar: 'y', baz: 'z' }, { delimiter: ';' } ); // Result: 'foo=x;bar=y;baz=z' // Pipe delimiter const pipeDelim = stringify( { a: '1', b: '2' }, { delimiter: '|' } ); // Result: 'a=1|b=2' // With nesting and custom delimiter const nestedSemicolon = stringify( { user: { name: 'John', age: '30' } }, { delimiter: ';' } ); // Result: 'user.name=John;user.age=30' ``` -------------------------------- ### Stringify an object to a query string Source: https://github.com/43081j/picoquery/blob/main/README.md Use the `stringify` function to convert a JavaScript object into a query string. Supports nested objects by default. ```ts import {stringify} from 'picoquery'; stringify({ foo: { bar: 123 } }); /* foo.bar=123 */ ``` -------------------------------- ### Configure defaultShouldSerializeObject Source: https://context7.com/43081j/picoquery/llms.txt Determines whether an object should be serialized directly or treated as a nested structure. Use this to define custom serialization behavior for specific classes. ```typescript import { stringify, defaultShouldSerializeObject } from 'picoquery'; // Dates are serialized by default defaultShouldSerializeObject(new Date()); // Result: true // Other objects are treated as nested defaultShouldSerializeObject({ foo: 'bar' }); // Result: false // Arrays are treated as nested defaultShouldSerializeObject(['a', 'b']); // Result: false // Custom shouldSerializeObject with fallback class StringifiableId { constructor(public id: string) {} toString() { return this.id; } } const customCheck = stringify( { userId: new StringifiableId('abc-123'), data: { x: 1 } }, { shouldSerializeObject: (val) => { if (val instanceof StringifiableId) return true; return defaultShouldSerializeObject(val); }, valueSerializer: (val) => String(val) } ); // Result: 'userId=abc-123&data.x=1' ``` -------------------------------- ### Customize value serialization Source: https://github.com/43081j/picoquery/blob/main/README.md Use valueSerializer to define custom logic for stringifying values. The function receives the value and key as arguments. ```ts stringify({foo: 'bar'}, { valueSerializer: (val) => String(val) + String(val) }); // foo=barbar ``` ```ts import {defaultValueSerializer, stringify} from 'picoquery'; stringify({foo: 'bar'}, { valueSerializer: (val, key) => { if (val instanceof Date) { return val.toISOString(); } // Call the original serializer otherwise return defaultValueSerializer(val, key); } }); ``` -------------------------------- ### Stringify with Custom Value Serializer Source: https://context7.com/43081j/picoquery/llms.txt Provide a custom function to transform values before they are serialized. The default serializer handles common types, but custom logic can be applied using `valueSerializer` and `shouldSerializeObject`. ```typescript import { stringify, defaultValueSerializer } from 'picoquery'; // Custom serializer for all values const customSerializer = stringify( { foo: 'bar' }, { valueSerializer: (value) => String(value).toUpperCase() } ); // Result: 'foo=BAR' // Handle custom objects with fallback to default const customWithFallback = stringify( { timestamp: new Date('2024-01-15'), name: 'test' }, { valueSerializer: (value, key) => { if (value instanceof Date) { return value.getTime().toString(); // Unix timestamp } return defaultValueSerializer(value, key); } } ); // Result: 'timestamp=1705276800000&name=test' // Custom class serialization class Money { constructor(public amount: number, public currency: string) {} toString() { return `${this.amount} ${this.currency}`; } } const moneySerializer = stringify( { price: new Money(99.99, 'USD') }, { shouldSerializeObject: (val) => val instanceof Money, valueSerializer: (value) => String(value) } ); // Result: 'price=99.99%20USD' ``` -------------------------------- ### Deserialize values with a custom function Source: https://github.com/43081j/picoquery/blob/main/README.md Provide a `valueDeserializer` function to transform values during parsing. The function receives the raw value and the deserialized key. ```ts parse('foo=300', { valueDeserializer: (value) => { const asNum = Number(value); return Number.isNaN(asNum) ? value : asNum; } }); // {foo: 300} ``` -------------------------------- ### Parse a query string Source: https://github.com/43081j/picoquery/blob/main/README.md Use the `parse` function to convert a query string into a JavaScript object. Supports nested objects by default. ```ts import {parse} from 'picoquery'; parse('foo.bar=abc&baz=def'); /* { foo: { bar: 'abc' }, baz: 'def' } */ ``` -------------------------------- ### Parse with custom delimiter in TypeScript Source: https://context7.com/43081j/picoquery/llms.txt Override the default '&' delimiter with a custom character or character code. ```typescript import { parse } from 'picoquery'; // Use semicolon as delimiter const semicolonDelim = parse('foo=x;bar=y;baz=z', { delimiter: ';' }); // Result: { foo: 'x', bar: 'y', baz: 'z' } // Can also use character code const charCodeDelim = parse('foo=x|bar=y', { delimiter: '|'.charCodeAt(0) // 124 }); // Result: { foo: 'x', bar: 'y' } // With nesting and custom delimiter const nestedSemicolon = parse('user.name=John;user.age=30', { delimiter: ';' }); // Result: { user: { name: 'John', age: '30' } } ``` -------------------------------- ### defaultShouldSerializeObject Function Source: https://context7.com/43081j/picoquery/llms.txt The default function that determines if an object-like value should be serialized directly rather than being treated as a nested object. By default, only Date objects are serialized directly. ```APIDOC ## defaultShouldSerializeObject ### Description The default function that determines if an object-like value should be serialized directly rather than being treated as a nested object. By default, only Date objects are serialized directly. ### Usage ```typescript import { stringify, defaultShouldSerializeObject } from 'picoquery'; // Dates are serialized by default defaultShouldSerializeObject(new Date()); // Result: true // Other objects are treated as nested defaultShouldSerializeObject({ foo: 'bar' }); // Result: false // Arrays are treated as nested defaultShouldSerializeObject(['a', 'b']); // Result: false // Custom shouldSerializeObject with fallback class StringifiableId { constructor(public id: string) {} toString() { return this.id; } } const customCheck = stringify( { userId: new StringifiableId('abc-123'), data: { x: 1 } }, { shouldSerializeObject: (val) => { if (val instanceof StringifiableId) return true; return defaultShouldSerializeObject(val); }, valueSerializer: (val) => String(val) } ); // Result: 'userId=abc-123&data.x=1' ``` ``` -------------------------------- ### Default Value Serializer Source: https://context7.com/43081j/picoquery/llms.txt The default function used by `stringify` to serialize values. It handles standard JavaScript types like strings, numbers, booleans, BigInts, and Dates. It can be imported and used as a fallback in custom serializers. ```typescript import { defaultValueSerializer } from 'picoquery'; // String values are URL-encoded defaultValueSerializer('hello world', 'key'); // Result: 'hello%20world' // Numbers are converted to strings defaultValueSerializer(42, 'key'); // Result: '42' // Large numbers are encoded defaultValueSerializer(1e21, 'key'); // Result: '1e%2B21' (encoded) // Booleans become 'true' or 'false' defaultValueSerializer(true, 'key'); // Result: 'true' // BigInt values defaultValueSerializer(BigInt(123), 'key'); // Result: '123' // Dates become ISO strings (URL-encoded) defaultValueSerializer(new Date('2024-01-15'), 'key'); // Result: '2024-01-15T00%3A00%3A00.000Z' // Infinity returns empty string defaultValueSerializer(Infinity, 'key'); // Result: '' ``` -------------------------------- ### Conditionally serialize objects Source: https://github.com/43081j/picoquery/blob/main/README.md Use `shouldSerializeObject` to control which objects are serialized as nested structures versus plain values. Requires `valueSerializer` for custom serialization. ```ts // Assuming `StringifableObject` returns its constructor value when `toString` // is called. stringify({ foo: new StringifiableObject('test') }, { shouldSerializeObject(val) { return val instanceof StringifableObject; }, valueSerializer: (value) => { return String(value); } }); // foo=test ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.