API reference - DarthJDG/Mangler.js GitHub Wiki
Globals
| Global | Description |
|---|---|
| Mangler() | The main entry point of the library, returns a mangler object built from the passed items. |
Mangler object properties
| Property | Description |
|---|---|
| .items[ ] | An array of items contained in the mangler object. |
Mangler object methods
| Method | Description |
|---|---|
| .add() | Adds items or arrays of items to the mangler object. |
| .aggregate() | Processes items in a loop and returns a single or grouped result. |
| .clear() | Removes all items from the mangler object. |
| .clone() | Creates a deep copy of the mangler object and all its items. |
| .copy() | Copies all items into a new mangler object and returns it. |
| .deflate() | Turns nested objects and arrays into flat objects. |
| .each() | Iterates through all items. |
| .end() | Loads a previous mangler object from the chain, before the last find, findOne or extract call. |
| .endAll() | Loads the mangler object from the top of the chain, before the first find, findOne or extract call. |
| .explore() | Traverses all nested objects and arrays in the items array, calling a function for each key/value pair. |
| .extract() | Extracts parts of items with path filters and returns a new mangler object with the result. |
| .filter() | Removes all items that do not pass the test. |
| .find() | Returns a new mangler object with items that pass the test. |
| .findOne() | Returns a new mangler object with the first item that passes the test. |
| .first() | Returns the first item that passes the test. |
| .get() | Returns the item with the given index. |
| .index() | Builds a lookup object from the items array, using object properties or a custom key generator. |
| .inflate() | Turns flat objects into nested objects and arrays. |
| .last() | Returns the last item that passes the test. |
| .limit() | Truncates the items array to a certain number of items. |
| .merge() | Copies properties of an object into all items. It can also merge arrays of objects. |
| .push() | Adds items to the mangler object. |
| .remove() | Remove items by index or test expression. |
| .removeItem() | Removes an item. |
| .rename() | Renames matching strings or object property names. |
| .test() | Checks if any of the items pass the test. |
| .transform() | Transforms all items' property names between snake_case, camelCase and TitleCase. |
Utility functions
| Function | Description |
|---|---|
| Mangler.aggregate() | Processes items in a loop and returns a single or grouped result. |
| Mangler.clone() | Create a deep copy of an object or array. |
| Mangler.compareType() | Checks if two values have the same type. Also works with constructors. |
| Mangler.deflate() | Turns nested objects and arrays into a flat object. |
| Mangler.each() | Iterate through items of an object or array, calling a function for each element. |
| Mangler.explore() | Traverses all nested objects and arrays, calling a function for each key/value pair. |
| Mangler.extract() | Extract parts of your data with path filters. |
| Mangler.filter() | Removes all array items or object properties that do not pass the test. |
| Mangler.find() | Returns an array of objects that pass the test. |
| Mangler.findOne() | Returns the first item of an iterable that passes the test. |
| Mangler.first() | Returns the first item of an iterable that passes the test. |
| Mangler.get() | Reads an object's item by index or key. |
| Mangler.getPath() | Reads a nested object's item by a path string of keys and indices. |
| Mangler.index() | Builds a lookup object using object properties or a custom key generator. |
| Mangler.inflate() | Turns a flat object into nested objects and arrays. |
| Mangler.isArray() | Checks if parameter is an array. |
| Mangler.isEmpty() | Checks if parameter is empty. Works with undefined, null, empty string and iterable objects. |
| Mangler.isMangler() | Checks if parameter is a mangler object. |
| Mangler.isObject() | Checks if parameter is an object literal. |
| Mangler.last() | Returns the last item of an iterable that passes the test. |
| Mangler.merge() | Copies properties from one object to another. Also works with arrays of objects. |
| Mangler.rename() | Renames matching strings in arrays or object property names. |
| Mangler.test() | Checks if the parameter passes a test. |
| Mangler.tokenize() | Break down an identifier name to an array of words. |
| Mangler.transform() | Transforms strings or object property names between snake_case, camelCase and TitleCase. |
Type handling
| Function | Description |
|---|---|
| Mangler.registerType() | Register handler functions for typed object instances. |
| Mangler.mergeType() | Merge handler bindings to add/remove features. |
| Mangler.removeType() | Unregisters a custom handler. |
| Mangler.getCloner() | Returns the cloning function for an object. |
| Mangler.getIterator() | Returns the iterator function for an object. |
| Mangler.getGetter() | Returns the getter function for an object. |