### Path String Example Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Provides an example of a path represented as a string, commonly used for accessing nested properties in a dot-separated format. ```bash # Path string user.colors.0 ``` -------------------------------- ### Query Syntax Examples in JavaScript Source: https://context7.com/ehmicky/wild-wild-path/llms.txt Demonstrates various query string syntaxes for accessing properties in nested objects and arrays using wild-wild-path's list and get functions. Covers deep access, wildcards, array slicing, regex, unions, and escaping special characters. ```javascript import { list, get, set } from 'wild-wild-path' const target = { users: [ { name: 'Alice', tags: ['admin', 'active'] }, { name: 'Bob', tags: ['user'] } ], 'key.with.dots': 'special', 'key with spaces': 'another' } // Deep properties - use dots for arrays too get(target, 'users.0.tags.0') // 'admin' // Shallow wildcard (*) - all direct children list(target, 'users.0.*') // ['Alice', ['admin', 'active']] // Deep wildcard (**) - all descendants list(target, '**') // [entire object, users array, user objects, 'Alice', tags, 'admin', ...] // Array slice (start:end) - end is exclusive list(target, 'users.0.tags.0:1') // ['admin'] // Slice from beginning list(target, 'users.0.tags.:1') // ['admin'] // Slice to end list(target, 'users.0.tags.1:') // ['active'] // Regexp in string query list(target, 'users.0./^t/') // [['admin', 'active']] // Case-insensitive regexp list(target, 'users.0./NAME/i') // ['Alice'] // Union - multiple queries (space-separated) list(target, 'users.0.name users.1.name') // ['Alice', 'Bob'] // Escaping dots in property names get(target, 'key\.with\.dots') // 'special' // Escaping spaces in property names get(target, 'key\ with\ spaces') // 'another' // Root access get(target, '.') // entire target object // Array query format (no escaping needed, recommended for dynamic input) get(target, ['key.with.dots']) // 'special' list(target, [['users', 0, 'name'], ['users', 1, 'name']]) // ['Alice', 'Bob'] ``` -------------------------------- ### Path Array Example in ES6 Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Shows a path represented as an array in ES6, which is the internal format used by the library for defining property access sequences. ```es6 // Path array ['user', 'colors', 0] ``` -------------------------------- ### Entries Option Example in JavaScript Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Demonstrates the 'entries' option in JavaScript for the `list()` function. When `entries` is `true`, it returns objects containing the value, path, and missing status of each property, instead of just the values. ```javascript const target = { firstName: 'Alice', lastName: 'Smith' } list(target, '*') // ['Alice', 'Smith'] list(target, '*', { entries: true }) // [ // { value: 'Alice', path: ['firstName'], missing: false }, // { value: 'Smith', path: ['lastName'], missing: false }, // ] ``` -------------------------------- ### Query Syntax Examples (JavaScript) Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Demonstrates how to represent queries programmatically using arrays, which are often preferred for dynamic inputs due to their speed and lack of need for escaping. This includes deep property access and unions. ```javascript // Deep properties of objects or arrays. // Symbol properties are always ignored. ['user', 'colors', 0] // Unions ("or") of queries are arrays of arrays. // There must be at least one item. [['colors'], ['name'], ['age']] ``` -------------------------------- ### Query Syntax Examples (Bash) Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Illustrates various ways to construct queries using strings, which are suitable for CLI usage and serialization. This includes deep property access, unions, wildcards, regular expressions, array indices, and slicing. ```bash # Deep properties of objects or arrays. # Dots are used for array indices, not brackets. # Symbol properties are always ignored. user.colors.0 # Unions ("or") of queries are space-delimited. # The string must not be empty. colors name age # Shallow wildcards target all properties/items of a single object/array user.* # Deep wildcards target all properties/items of 0, 1 or many objects/arrays user.** **.colors # Regexps match property names user./name/ # Flags can be used, e.g. to make it case-insensitive user./name/i # ^ $ must be used to match from the beginning or until the end user./^name$/i # Array indices are integers user.colors.0 # Array indices can be negative. # -1 is the last item. # -0 is the item after it, which can be used to append. user.colors.-1 # Array slices. Goes from the start (included) to the end index (excluded). user.colors.0:2 # The start index defaults to 0, i.e. the beginning user.colors.:2 # The end index defaults to -0, i.e. the end user.colors.0: user.colors.: # Dots, spaces and backslashes in property names must be escaped name\ with\ spaces name\.with\.dots name\\with\\backslashes # Ambiguous property names must be escaped with a backslash at the beginning. # This includes properties that: # - Are integers but are not array elements # - Have multiple slashes and start with one name.\0 name.\/not_a_regexp/ # A leading dot can optionally be used. It is ignored. user.colors .user.colors # Root value . # Empty string properties user..colors ``` -------------------------------- ### Array Slices in ES6 Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Demonstrates array slicing in ES6 using objects with 'type: slice', 'from', and 'to' properties. It covers slices with specified start and end, default start (0), and default end (-0). ```es6 // Array slices. Goes from the start (included) to the end index (excluded). ['user', 'colors', { type: 'slice', from: 0, to: 2 }] // The start index defaults to 0, i.e. the beginning ['user', 'colors', { type: 'slice', to: 2 }] // The end index defaults to -0, i.e. the end ['user', 'colors', { type: 'slice', from: 0 }] ['user', 'colors', { type: 'slice' }] ``` -------------------------------- ### Install wild-wild-path using npm Source: https://context7.com/ehmicky/wild-wild-path/llms.txt Installs the wild-wild-path library using the npm package manager. This command is typically run in a Node.js environment. ```bash npm install wild-wild-path ``` -------------------------------- ### Missing Option Example in JavaScript Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Explains the 'missing' option in JavaScript for `set()` and `list()` functions. It controls whether properties not defined in the target are ignored or included, particularly useful when dealing with potentially undefined paths. ```javascript const target = {} set(target, 'name', 'Alice') // { name: 'Alice' } set(target, 'name', 'Alice', { missing: false }) // {} list(target, 'name') // [] list(target, 'name', { missing: true, entries: true }) // [{ value: undefined, path: ['name'], missing: true }] ``` -------------------------------- ### Mutate Option Example in JavaScript Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Illustrates the 'mutate' option in JavaScript for the `set()` function. When `mutate` is `false` (default), the target object is cloned. When `true`, the target object is mutated directly for performance. ```javascript const target = {} console.log(set(target, 'name', 'Alice')) // { name: 'Alice' } console.log(target) // {} console.log(set(target, 'name', 'Alice', { mutate: true })) // { name: 'Alice' } console.log(target) // { name: 'Alice' } ``` -------------------------------- ### Get Property Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Retrieves the value of the first property that matches the specified query. The query can be a dot-delimited string, an array of path segments, or include wildcards and regexps. ```APIDOC ## GET /get ### Description Retrieves the value of the first property matching the query. ### Method `get` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const target = { settings: { colors: ['red', 'blue'] } } get(target, 'settings.colors.0') // 'red' get(target, ['settings', 'colors', 0]) // 'red' ``` ### Response #### Success Response (200) - **value** (any | undefined) - The value of the first matching property, or undefined if no match is found. #### Response Example ```json "red" ``` ``` -------------------------------- ### Handling Undefined Values with has() in JavaScript Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Demonstrates how the `has()` function in JavaScript distinguishes between properties that are explicitly set to `undefined` and properties that are missing entirely. It also shows the behavior of `get()` and `list()` with the `entries` and `missing` options. ```javascript const target = { name: undefined } has(target, 'name') // true has(target, 'colors') // false get(target, 'name') // undefined get(target, 'colors') // undefined get(target, 'name', { entries: true, missing: true }) // { value: undefined, path: ['name'], missing: false } get(target, 'colors', { entries: true, missing: true }) // { value: undefined, path: ['colors'], missing: true } list(target, '*') // [undefined] list(target, '*', { entries: true }) // [{ value: undefined, path: ['name'], missing: false }] ``` -------------------------------- ### Get object property using dot notation and array queries Source: https://context7.com/ehmicky/wild-wild-path/llms.txt Demonstrates retrieving object properties using the `get` method from the wild-wild-path library. It supports basic dot-delimited strings, array index access, programmatic array queries, deep wildcards, and options for detailed entry information. Returns `undefined` if the property is not found. ```javascript import { get } from 'wild-wild-path' const target = { users: [ { name: 'Alice', role: 'admin' }, { name: 'Bob', role: 'user' } ], settings: { theme: 'dark', notifications: { email: true, push: false } } } // Basic property access get(target, 'settings.theme') // 'dark' // Array index access (using dot notation, not brackets) get(target, 'users.0.name') // 'Alice' // Array query format (no escaping needed) get(target, ['users', 0, 'name']) // 'Alice' // Deep wildcard - returns first match get(target, '**.name') // 'Alice' // With entries option for full metadata get(target, 'settings.theme', { entries: true }) // { value: 'dark', path: ['settings', 'theme'], missing: false } // Missing property returns undefined get(target, 'settings.language') // undefined ``` -------------------------------- ### Get Object Property using Dot-Delimited Path Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Demonstrates how to retrieve a specific object property using a dot-delimited path string or an array of path segments. This function returns the value of the first matching property or undefined if not found. ```javascript const target = { settings: { colors: ['red', 'blue'] } } get(target, 'settings.colors.0') // 'red' get(target, ['settings', 'colors', 0]) // 'red' ``` -------------------------------- ### Regexps for Property Matching in ES6 Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Illustrates how to use regular expressions in ES6 to match property names. It shows basic matching, case-insensitive matching with the 'i' flag, and anchoring matches to the beginning ('^') or end ('$') of property names. ```es6 // Regexps match property names ['user', /name/] // Flags can be used, e.g. to make it case-insensitive ['user', /name/i] // ^ $ must be used to match from the beginning or until the end ['user', /^name$/i] ``` -------------------------------- ### Root and Empty Strings in ES6 Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Illustrates how to represent the root value with an empty array `[]` and how to target properties with empty string names in ES6 query arrays. ```es6 // Root value [] // Empty string properties ['user', '', 'colors'] ``` -------------------------------- ### List Matching Object Properties Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Demonstrates retrieving all properties that match a given query. The `list` function supports various path notations including unions, regexps, wildcards, and array slices, returning results as an array. It can also return entries with path and missing information when the `entries: true` option is used. ```javascript const target = { userOne: { firstName: 'John', lastName: 'Doe', age: 72 }, userTwo: { firstName: 'Alice', colors: ['red', 'blue', 'yellow'] }, } list(target, 'userOne.firstName userTwo.colors.0') // ['John', 'red'] list(target, [ ['userOne', 'firstName'], ['userTwo', 'colors', 0], ]) // ['John', 'red'] list(target, 'userOne./Name/') // ['John', 'Doe'] list(target, ['userOne', /Name/]) // ['John', 'Doe'] list(target, 'userTwo.colors.*') // ['red', 'blue', 'yellow'] list(target, 'userTwo.colors.0:2') // ['red', 'blue'] list(target, '**.firstName') // ['John', 'Alice'] list(target, 'userOne.*', { entries: true }) // [ // { value: 'John', path: ['userOne', 'firstName'], missing: false }, // { value: 'Doe', path: ['userOne', 'lastName'], missing: false }, // { value: 72, path: ['userOne', 'age'], missing: false }, // ] ``` -------------------------------- ### List Matching Properties Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Retrieves all properties that match the specified query and returns them as an array. Supports various path syntaxes including wildcards, regexps, slices, and unions. ```APIDOC ## GET /list ### Description Returns all properties matching the query, as an array. ### Method `list` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const target = { userOne: { firstName: 'John', lastName: 'Doe', age: 72 }, userTwo: { firstName: 'Alice', colors: ['red', 'blue', 'yellow'] }, } list(target, 'userOne.firstName userTwo.colors.0') // ['John', 'red'] list(target, 'userOne./Name/') // ['John', 'Doe'] list(target, 'userTwo.colors.*') // ['red', 'blue', 'yellow'] list(target, 'userTwo.colors.0:2') // ['red', 'blue'] list(target, '**.firstName') // ['John', 'Alice'] ``` ### Response #### Success Response (200) - **values** (any[]) - An array containing the values of all properties that match the query. #### Response Example ```json ["John", "red"] ``` ``` -------------------------------- ### Iterate Over Matching Object Properties Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Illustrates how to iterate over all properties matching a query using an iterable. This method is more memory-efficient than `list()` for large datasets but may be slower. ```javascript const target = { settings: { colors: ['red', 'blue'] } } for (const color of iterate(target, 'settings.colors.*')) { console.log(color) // 'red', 'blue' } ``` -------------------------------- ### Options Reference for wild-wild-path Functions in JavaScript Source: https://context7.com/ehmicky/wild-wild-path/llms.txt Illustrates the usage of various options available in wild-wild-path's list and set functions. Options control the output format, handling of missing properties, mutation behavior, sorting, traversal order, and inclusion of specific property types. ```javascript import { list, set, get } from 'wild-wild-path' // entries: Return full metadata instead of just values list({ a: 1, b: 2 }, '*', { entries: true }) // [ // { value: 1, path: ['a'], missing: false }, // { value: 2, path: ['b'], missing: false } // ] // missing: Control handling of non-existent properties set({}, 'x.y', 1) // { x: { y: 1 } } -- missing: true by default for set() set({}, 'x.y', 1, { missing: false }) // {} -- property not created list({}, 'x', { missing: true, entries: true }) // [{ value: undefined, path: ['x'], missing: true }] // mutate: Modify in place instead of cloning const obj = { x: 1 } set(obj, 'x', 2) console.log(obj.x) // 1 (unchanged) set(obj, 'x', 2, { mutate: true }) console.log(obj.x) // 2 (mutated) // sort: Lexicographic order for object properties list({ c: 3, a: 1, b: 2 }, '*', { sort: true }) // [1, 2, 3] // childFirst: Children before parents in results list({ user: { name: 'X' } }, 'user.**') // [{ name: 'X' }, 'X'] list({ user: { name: 'X' } }, 'user.**', { childFirst: true }) // ['X', { name: 'X' }] // leaves: Only return leaf nodes list({ a: { b: { c: 1 } } }, '**', { leaves: true }) // [1] // roots: Only return root matches list({ a: { b: 1 } }, 'a.**', { roots: true }) // [{ b: 1 }] // shallowArrays: Wildcards don't recurse into arrays list([{ x: 1 }, { x: 2 }], '**') // [[...], { x: 1 }, 1, { x: 2 }, 2] list([{ x: 1 }, { x: 2 }], '**', { shallowArrays: true }) // [[{ x: 1 }, { x: 2 }]] // classes: Include class instance properties in wildcards class User { constructor(name) { this.name = name } } list({ user: new User('Alice') }, 'user.*') // [] list({ user: new User('Alice') }, 'user.*', { classes: true }) // ['Alice'] // inherited: Include inherited properties in wildcards const proto = { inherited: 'value' } const obj2 = Object.create(proto) obj2.own = 'prop' list(obj2, '*') // ['prop'] list(obj2, '*', { inherited: true }) // ['prop', 'value'] ``` -------------------------------- ### Wildcards in ES6 Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Demonstrates the use of shallow and deep wildcards in ES6 for targeting properties and items in objects and arrays. Shallow wildcards target a single level, while deep wildcards target zero, one, or multiple levels. ```es6 // Shallow wildcards target all properties/items of a single object/array ['user', { type: 'any' }] // Deep wildcards target all properties/items of 0, 1 or many objects/arrays ['user', { type: 'anyDeep' }] [{ type: 'anyDeep' }, 'colors'] ``` -------------------------------- ### List matching properties with `list` method Source: https://context7.com/ehmicky/wild-wild-path/llms.txt Demonstrates using the `list` method to retrieve all properties that match a given query. This method supports complex queries including unions of paths, regular expressions for property names, array slices, and deep wildcards. It can return raw values, full entry metadata, or filtered results based on options like `sort`, `leaves`, and `roots`. ```javascript import { list } from 'wild-wild-path' const target = { userOne: { firstName: 'John', lastName: 'Doe', age: 72 }, userTwo: { firstName: 'Alice', lastName: 'Smith', colors: ['red', 'blue', 'yellow'] } } // Union query - multiple paths list(target, 'userOne.firstName userTwo.colors.0') // ['John', 'red'] // Regexp query - match property names list(target, 'userOne./Name/') // ['John', 'Doe'] // Array regexp format list(target, ['userOne', /Name/]) // ['John', 'Doe'] // Shallow wildcard - all items in array list(target, 'userTwo.colors.*') // ['red', 'blue', 'yellow'] // Array slice - indices 0 to 2 (exclusive) list(target, 'userTwo.colors.0:2') // ['red', 'blue'] // Deep wildcard - find all firstName properties list(target, '**.firstName') // ['John', 'Alice'] // With entries for full metadata list(target, 'userOne.*', { entries: true }) // [ // { value: 'John', path: ['userOne', 'firstName'], missing: false }, // { value: 'Doe', path: ['userOne', 'lastName'], missing: false }, // { value: 72, path: ['userOne', 'age'], missing: false } // ] // Sorted results list({ b: 2, a: 1 }, '*', { sort: true }) // [1, 2] // Only leaf values (no intermediate objects) list({ user: { name: 'Alice' } }, 'user.**', { leaves: true }) // ['Alice'] // Only root values (no children) list({ user: { name: 'Alice' } }, 'user.**', { roots: true }) // [{ name: 'Alice' }] ``` -------------------------------- ### Iterate Matching Properties Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Returns an iterable object for all properties matching the specified query. This method is more memory-efficient than `list()` for large datasets, as it yields values one by one. ```APIDOC ## GET /iterate ### Description Returns all properties matching the query, as an iterable. ### Method `iterate` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const target = { settings: { colors: ['red', 'blue'] } } for (const color of iterate(target, 'settings.colors.*')) { console.log(color) // 'red', 'blue' } ``` ### Response #### Success Response (200) - **iterator** (Iterable) - An iterable object yielding the values of matching properties. #### Response Example ```json // Example output from iterating: // "red" // "blue" ``` ``` -------------------------------- ### Array Indices in ES6 Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Explains how to use integer array indices in ES6, including positive indices and negative indices for accessing elements from the end of an array. It also shows how '-0' can be used for appending. ```es6 // Array indices are integers, not strings ['user', 'colors', 0] // Array indices can be negative. // -1 is the last item. // -0 is the item after it, which can be used to append. ['user', 'colors', -1] ``` -------------------------------- ### Match Only Root Properties Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md The 'roots' option, when true, ensures that only root properties are matched. A property is ignored if one of its parents also matches the query. ```javascript const target = { user: { name: 'Alice' } } list(target, 'user.**') // [{ name: 'Alice' }, 'Alice'] list(target, 'user.**', { roots: true }) // [{ name: 'Alice' }] ``` -------------------------------- ### Traverse Class Instance Properties Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md The 'classes' option, when true, allows wildcards and regexps to traverse properties of non-plain objects like class instances. By default, these properties are ignored. ```javascript const target = { user: new User({ name: 'Alice' }) } list(target, 'user.*') // [] list(target, 'user.*', { classes: true }) // ['Alice'] ``` -------------------------------- ### Check Property Existence Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Checks if any property in the target object matches the given query. Returns a boolean indicating whether a match was found. ```APIDOC ## GET /has ### Description Returns whether the query matches any property. ### Method `has` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const target = { settings: { lastName: undefined, colors: ['red', 'blue'] } } has(target, 'settings.firstName') // false has(target, ['settings', 'firstName']) // false has(target, 'settings.lastName') // true ``` ### Response #### Success Response (200) - **exists** (boolean) - True if at least one property matches the query, false otherwise. #### Response Example ```json true ``` ``` -------------------------------- ### set(target, query, value, options?) Source: https://context7.com/ehmicky/wild-wild-path/llms.txt Sets all properties matching the query to the given value. By default, it returns a deep clone (immutable), but can mutate the target in place with the `mutate: true` option. ```APIDOC ## set(target, query, value, options?) ### Description Sets all properties matching the query to the given value. Returns a deep clone by default (immutable), or mutates in place with `mutate: true`. ### Method PUT (conceptual - modifies data) ### Endpoint N/A (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { set } from 'wild-wild-path' const target = { colors: ['red', 'blue'], user: { name: 'Alice' } } // Set single property (returns new object) set(target, 'colors.0', 'yellow') // Negative index - last item set(target, 'colors.-1', 'green') // Negative zero - append to array set(target, 'colors.-0', 'purple') // Wildcard - set all array items set(target, 'colors.*', 'black') // Create nested path automatically set({}, 'user.0.profile.name', 'Bob') // Disable auto-creation of missing paths set({}, 'user.name', 'Bob', { missing: false }) // Mutate in place (faster, but has side effects) const mutableTarget = { count: 0 } set(mutableTarget, 'count', 1, { mutate: true }) // Set with array query format set({ data: { value: 100 } }, ['data', 'value'], 200) ``` ### Response #### Success Response (200) - **target** (object) - A deep clone of the target object with the specified properties updated, or the mutated original object if `mutate: true` was used. #### Response Example ```json { "colors": ["yellow", "blue"], "user": {"name": "Alice"} } ``` ``` -------------------------------- ### Check if Object Property Exists Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Shows how to check if any property in an object matches a given query. The `has` function returns a boolean indicating whether a match was found. ```javascript const target = { settings: { lastName: undefined, colors: ['red', 'blue'] } } has(target, 'settings.firstName') // false has(target, ['settings', 'firstName']) // false has(target, 'settings.lastName') // true ``` -------------------------------- ### iterate(target, query, options?) Source: https://context7.com/ehmicky/wild-wild-path/llms.txt Returns an iterable for all properties matching the query. This method is memory-efficient for large result sets compared to `list()`, though slightly slower. ```APIDOC ## iterate(target, query, options?) ### Description Returns an iterable for all properties matching the query. Uses less memory than `list()` for large result sets, but is slightly slower. ### Method GET (conceptual - returns an iterator) ### Endpoint N/A (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { iterate } from 'wild-wild-path' const target = { products: [ { id: 1, name: 'Widget', price: 9.99 }, { id: 2, name: 'Gadget', price: 19.99 }, { id: 3, name: 'Gizmo', price: 29.99 } ] } // Iterate over all product names for (const name of iterate(target, 'products.*.name')) { console.log(name) } // With entries for path information for (const entry of iterate(target, 'products.*.price', { entries: true })) { console.log(`${entry.path.join('.')} = ${entry.value}`) } // Collect specific items using spread const expensiveProducts = [...iterate(target, 'products.1:.name')] ``` ### Response #### Success Response (Iterator) - **value** (any) - The value of the property. - **path** (array) - The path to the property (if `entries: true` is used). #### Response Example (Iterator yields values or entries) ``` -------------------------------- ### Child-First Traversal Order Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md The 'childFirst' option controls the traversal order when dealing with unions or deep wildcards. When true, children are returned before their parents. ```javascript const target = { user: { name: 'Alice' } } list(target, 'user.**') // [{ name: 'Alice' }, 'Alice'] list(target, 'user.**', { childFirst: true }) // ['Alice', { name: 'Alice' }] ``` -------------------------------- ### Escaping in ES6 Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md Shows that escaping is not necessary in ES6 query arrays for property names containing spaces, dots, backslashes, or when using numbers or regex-like strings as literal property names. ```es6 // Escaping is not necessary with query arrays ['name with spaces'] ['name.with.dots'] ['name\with\backslashes'] ['name', '0'] ['name', '/not_a_regexp/'] ``` -------------------------------- ### Include Inherited Properties Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md The 'inherited' option, when true, includes inherited properties in the traversal results. By default, inherited and non-enumerable properties are ignored. ```javascript const target = Object.create({ inheritedProp: 'value' }, { ownProp: { value: 'ownValue', enumerable: true } }) list(target, '*') // ['ownValue'] list(target, '*', { inherited: true }) // ['ownValue', 'value'] ``` -------------------------------- ### Check for property existence using `has` method Source: https://context7.com/ehmicky/wild-wild-path/llms.txt Illustrates how to check for the existence of properties within an object using the `has` method. This method correctly distinguishes between properties that are explicitly set to `undefined` and those that are missing entirely. It supports string queries, array queries, and wildcards. ```javascript import { has } from 'wild-wild-path' const target = { user: { firstName: 'John', lastName: undefined, // Explicitly set to undefined address: { city: 'NYC', zip: '10001' } } } // Property exists has(target, 'user.firstName') // true // Property exists but is undefined has(target, 'user.lastName') // true // Property does not exist has(target, 'user.middleName') // false // Deep property check has(target, 'user.address.city') // true // Wildcard check - any property in user has(target, 'user.*') // true // Check with array query format has(target, ['user', 'address', 'city']) // true ``` -------------------------------- ### Iterate Over Object Properties with wild-wild-path Source: https://context7.com/ehmicky/wild-wild-path/llms.txt The `iterate` function returns an iterable for all properties matching a given query. It is memory-efficient for large result sets and can optionally include path information with the `entries: true` option. ```javascript import { iterate } from 'wild-wild-path' const target = { products: [ { id: 1, name: 'Widget', price: 9.99 }, { id: 2, name: 'Gadget', price: 19.99 }, { id: 3, name: 'Gizmo', price: 29.99 } ] } // Iterate over all product names for (const name of iterate(target, 'products.*.name')) { console.log(name) } // 'Widget' // 'Gadget' // 'Gizmo' // With entries for path information for (const entry of iterate(target, 'products.*.price', { entries: true })) { console.log(`${entry.path.join('.')} = ${entry.value}`) } // 'products.0.price = 9.99' // 'products.1.price = 19.99' // 'products.2.price = 29.99' // Collect specific items using spread const expensiveProducts = [...iterate(target, 'products.1:.name')] // ['Gadget', 'Gizmo'] ``` -------------------------------- ### Match Only Leaf Properties Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md The 'leaves' option, when true, ensures that only leaf properties are matched. A property is ignored if one of its children also matches the query. ```javascript const target = { user: { name: 'Alice' } } list(target, 'user.**') // [{ name: 'Alice' }, 'Alice'] list(target, 'user.**', { leaves: true }) // ['Alice'] ``` -------------------------------- ### remove(target, query, options?) Source: https://context7.com/ehmicky/wild-wild-path/llms.txt Deletes all properties matching the query. By default, it returns a deep clone (immutable), but can mutate the target in place with the `mutate: true` option. ```APIDOC ## remove(target, query, options?) ### Description Deletes all properties matching the query. Returns a deep clone by default (immutable), or mutates in place with `mutate: true`. ### Method DELETE (conceptual - removes data) ### Endpoint N/A (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { remove } from 'wild-wild-path' const target = { user: { firstName: 'John', lastName: 'Doe', age: 72, email: 'john@example.com' } } // Remove single property remove(target, 'user.age') // Remove with regexp - all *Name properties remove(target, 'user./Name/') // Array regexp format remove(target, ['user', /Name/]) // Remove from array const arrayTarget = { items: ['a', 'b', 'c', 'd'] } remove(arrayTarget, 'items.1') // Remove with wildcard remove({ data: { x: 1, y: 2, z: 3 } }, 'data.*') // Mutate in place const mutableTarget = { temp: 'value', keep: 'this' } remove(mutableTarget, 'temp', { mutate: true }) ``` ### Response #### Success Response (200) - **target** (object) - A deep clone of the target object with the specified properties removed, or the mutated original object if `mutate: true` was used. #### Response Example ```json { "user": { "firstName": "John", "lastName": "Doe", "email": "john@example.com" } } ``` ``` -------------------------------- ### Set Properties in Objects and Arrays with Queries (JavaScript) Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md The `set` function modifies properties within a target object or array based on a provided query. It supports various query formats, including dot notation, array indices, wildcards, and regular expressions. The function returns a deep clone of the target by default, unless the `mutate` option is set to `true`. ```javascript const target = { colors: ['red', 'blue'] } set(target, 'colors.0', 'yellow') // ['yellow', 'blue'] set(target, ['colors', 0], 'yellow') // ['yellow', 'blue'] set(target, 'colors.-1', 'yellow') // ['red', 'yellow'] set(target, 'colors.-0', 'yellow') // ['red', 'blue', 'yellow'] set(target, 'colors.*', 'yellow') // ['yellow', 'yellow'] set({}, 'user.0.color', 'red') // { user: [{ color: 'red' }] } set({}, 'user.0.color', 'red', { missing: false }) // {} ``` -------------------------------- ### Set Object Properties with wild-wild-path Source: https://context7.com/ehmicky/wild-wild-path/llms.txt The `set` function modifies properties matching a query to a new value. By default, it returns a deep clone (immutable), but can mutate the original object in place using the `mutate: true` option. It supports negative indexing, wildcards, and automatic creation of nested paths. ```javascript import { set } from 'wild-wild-path' const target = { colors: ['red', 'blue'], user: { name: 'Alice' } } // Set single property (returns new object) set(target, 'colors.0', 'yellow') // { colors: ['yellow', 'blue'], user: { name: 'Alice' } } // Original is unchanged console.log(target.colors[0]) // 'red' // Negative index - last item set(target, 'colors.-1', 'green') // { colors: ['red', 'green'], user: { name: 'Alice' } } // Negative zero - append to array set(target, 'colors.-0', 'purple') // { colors: ['red', 'blue', 'purple'], user: { name: 'Alice' } } // Wildcard - set all array items set(target, 'colors.*', 'black') // { colors: ['black', 'black'], user: { name: 'Alice' } } // Create nested path automatically set({}, 'user.0.profile.name', 'Bob') // { user: [{ profile: { name: 'Bob' } }] } // Disable auto-creation of missing paths set({}, 'user.name', 'Bob', { missing: false }) // {} // Mutate in place (faster, but has side effects) const mutableTarget = { count: 0 } set(mutableTarget, 'count', 1, { mutate: true }) console.log(mutableTarget.count) // 1 // Set with array query format set({ data: { value: 100 } }, ['data', 'value'], 200) // { data: { value: 200 } } ``` -------------------------------- ### Sort Object Properties Lexicographically Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md The 'sort' option, when set to true, sorts sibling object properties by their lexicographical order of names. This affects the output of list() and iterate() methods. ```javascript const target = { lastName: 'Doe', firstName: 'John' } list(target, '*') // ['Doe', 'John'] list(target, '*', { sort: true }) // ['John', 'Doe'] ``` -------------------------------- ### Shallow Array Traversal Source: https://github.com/ehmicky/wild-wild-path/blob/main/README.md The 'shallowArrays' option prevents wildcards from recursing into arrays. Array items can still be matched using indices or slices. ```javascript const target = [{ name: 'Alice' }, { name: 'Bob' }] list(target, '**') // [ // [{ name: 'Alice' }, { name: 'Bob' }], // { name: 'Alice' }, // 'Alice', // { name: 'Bob' }, // 'Bob', // ] list(target, '**', { shallowArrays: true }) // [ // [{ name: 'Alice' }, { name: 'Bob' }], // ] ``` -------------------------------- ### Remove Object Properties with wild-wild-path Source: https://context7.com/ehmicky/wild-wild-path/llms.txt The `remove` function deletes properties matching a query. Similar to `set`, it returns a deep clone by default but can mutate in place with `mutate: true`. It supports regular expressions for property matching and array manipulation. ```javascript import { remove } from 'wild-wild-path' const target = { user: { firstName: 'John', lastName: 'Doe', age: 72, email: 'john@example.com' } } // Remove single property remove(target, 'user.age') // { user: { firstName: 'John', lastName: 'Doe', email: 'john@example.com' } } // Remove with regexp - all *Name properties remove(target, 'user./Name/') // { user: { age: 72, email: 'john@example.com' } } // Array regexp format remove(target, ['user', /Name/]) // { user: { age: 72, email: 'john@example.com' } } // Remove from array const arrayTarget = { items: ['a', 'b', 'c', 'd'] } remove(arrayTarget, 'items.1') // { items: ['a', undefined, 'c', 'd'] } // Remove with wildcard remove({ data: { x: 1, y: 2, z: 3 } }, 'data.*') // { data: {} } // Mutate in place const mutableTarget = { temp: 'value', keep: 'this' } remove(mutableTarget, 'temp', { mutate: true }) console.log(mutableTarget) // { keep: 'this' } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.