npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

craydent-array

v1.0.2

Published

Node module to extend array functionality and simplify code for maintainability and readability

Downloads

48

Readme

Craydent 1.0.2

by Clark Inada

Craydent is all inclusive utility library. There are several ways to use the library in NodeJS. More detailed documentation on constants can be found at Craydent Properties. More detailed documentation on methods can be found at Craydent Methods

// require with prototypes - this require will add prototypes to extend classes and add two constants ($c, $g) to the global space.
// $g is an alias to global and $c is the constant containing all the utility methods and properties.
require('craydent-array');
$c.logit($c.VERSION);
arr.prototypedMethod(args);
// require no conflict - this require is the fully modular version with no global constants, prototypes, or methods.
var $c = require('craydent-array/noConflict');
$c.logit($c.VERSION);
$c.prototypedMethod(arr, args);
// require global - this require constants and methods in the global space and add prototypes to extend classes.
// $g is an alias to global and $c is the constant containing all the utility methods and properties.
require('craydent-array/global');
logit($c.VERSION);
arr.prototypedMethod(args);

Categories

Constants

| | | | | ----- | ----- | ----- | | CONSOLE_COLORS (Object) |LOCAL_IP (String) |TEMPLATE_TAG_CONFIG (Object) | DEBUG_MODE (Boolean) |MODULES_LOADED (Object) |TEMPLATE_VARS (Array) | ERROR_TYPES (Array) |PUBLIC_IP (String) |VERSION (String) | HTTP_STATUS_TEMPLATE (Object) |RESPONSES (Object) |

Featured

Array


add


Info: Array class extension to perform push and update indexes if used

Return: (Bool) Value to indicate success or failure

Parameters:

  • value: (Object) value to add

Overloads:

None


aggregate


Info: Array class extension to perform mongo style aggregation

Return: (Documents) returns an array of aggregates

Parameters:

  • pipelines: (Array) Array of stages defined in mongodb. ($project, $match, $redact, $limit, $skip, $unwind, $group, $sample, $sort, $lookup, $out)

Overloads:

None


average


Info: Array class extension to perform average of all the values (any value which is not a number is skipped).

Return: (number)

Parameters:

None

Overloads:

None


find


Info: Array class extension to use mongo or sql queries (Alias of Where minus the limit argument)

Return: (Array)

Parameters:

  • condition: (WhereCondition | string) Query following find/where clause syntax

Overloads:

Parameters

  • condition: (WhereCondition | string) Query following find/where clause syntax
  • projection: (Fields | string) Indicate which properties to return

Parameters

  • condition: (WhereCondition | string) Query following find/where clause syntax
  • useReference: (Bool) Flag to make a copy instead of using references

findOne


Info: Array class extension to use mongo or sql queries returning the first item match

Return: (T)

Parameters:

  • condition: (WhereCondition | string) Query following find/where clause syntax

Overloads:

Parameters

  • condition: (WhereCondition | string) Query following find/where clause syntax
  • projection: (Fields | string) Indicate which properties to return

Parameters

  • condition: (WhereCondition | string) Query following find/where clause syntax
  • useReference: (Bool) Flag to make a copy instead of using references

parallelEach


Info: Array class extension to perform push and update indexes if used

Return: (Bool) Value to indicate success or failure

Parameters:

  • value: (Object) value to add

Overloads:

None


stdev


Info: Array class extension to perform standard deviation (any value which is not a number is 0).

Return: (number | NaN) returns the standard deviation of the array of numbers

Parameters:

None

Overloads:

None


sum


Info: Array class extension to perform summation of all the values (any value which is not a number is 0).

Return: (number | NaN) returns the sum of the array of numbers

Parameters:

None

Overloads:

None


where


Info: Array class extension to use mongo or sql queries

Return: (Array) returns a filtered subset of the array.

Parameters:

  • condition: (WhereCondition) Query following mongo find/where clause syntax

Overloads:

Parameters

  • condition: (WhereCondition) Query following mongo find/where clause syntax
  • limit: (number) Limit the number of the results returned.

Parameters

  • condition: (WhereCondition) Query following mongo find/where clause syntax
  • projection: (Object) Indicate which properties to return

Parameters

  • condition: (WhereCondition) Query following mongo find/where clause syntax
  • useReference: (Bool) Flag to make a copy instead of using references

Parameters

  • condition: (WhereCondition) Query following mongo find/where clause syntax
  • projection: (Object) Indicate which properties to return
  • limit: (Int) Limit the number of the results returned.

Parameters

  • condition: (WhereCondition) Query following mongo find/where clause syntax
  • useReference: (Bool) Flag to make a copy instead of using references
  • limit: (Int) Limit the number of the results returned.

Parameters

  • condition: (WhereIterator) The funciton invoked per iteration.
  • limit: (number) Limit the number of the results returned.

Parameters

  • condition: (WhereIterator) The funciton invoked per iteration.
  • projection: (Object) Indicate which properties to return

Parameters

  • condition: (WhereIterator) The funciton invoked per iteration.
  • useReference: (Bool) Flag to make a copy instead of using references

Parameters

  • condition: (WhereIterator) The funciton invoked per iteration.
  • projection: (Object) Indicate which properties to return
  • limit: (Int) Limit the number of the results returned.

Parameters

  • condition: (WhereIterator) The funciton invoked per iteration.
  • useReference: (Bool) Flag to make a copy instead of using references
  • limit: (Int) Limit the number of the results returned.

Methods

Array


buildTree


Info: Array class extension to create a parent/child hierarchy

Return: (Array) returns a hierarchical array.

Parameters:

  • parentFinder: (TreeParentFinder) Function to determine the parent. Should return a boolean value and is passed the current item as an argument.
  • childFinder: (String|TreeChildFinder) Property name of the object to use as a grouping.
  • options?: (TreeOptions) Options to customize properties, Valid property is:childProperty

Overloads:

None


condense


Info: Array class extension to reduce the size of the Array removing blank strings, undefined's, and nulls

Return: (Array) returns a condensed version of the array.

Parameters:

  • check_values?: (Bool) Set craydent_ctx flag to remove duplicates

Overloads:

None


createIndex


Info: Array class extension to create indexes for faster searches during where

Return: (Array | Bool) returns the Array if successfull otherwise false.

Parameters:

  • properties: (string) Property or comma delimited property list to index.

Overloads:

Parameters

  • indexes: (Array) Array of properties to index

delete


Info: Array class extension to delete records

Return: (Array) returns a list of the deleted objects.

Parameters:

  • condition: (WhereCondition) Query following find/where clause syntax
  • justOne?: (Bool) Flag for deleting just one records [Default is: true]

Overloads:

None


distinct


Info: Array class extension to get all unique records by fields specified

Return: (Array) returns an array with distinct values

Parameters:

  • fields: (String|Array) Fields to use as the projection and unique comparison (comma delimited) or array of fields
  • condition?: (String|WhereCondition) Query following SQL where clause syntax

Overloads:

None


emit


Info: Call the next function(s) in queue

Return: (Array)

Parameters:

  • event: (String) Event to trigger.
  • ...infinite: (any) any number of arguments can be passed and will be applied to listening functions as arguments.

Overloads:

None


filter


Info: Array class extension to implement filter

Return: (Array)

Parameters:

  • func: (ArrayIterator) Callback function used to determine if value should be returned. Callback will get the current item, index, context as arguments.
  • craydent_ctxs?: (any) Specify the context on callback function

Overloads:

None


group


Info: Array class extension to group records by fields

Return: (Array)

Parameters:

  • params: (GroupOptions) specs with common properties:(Object) key(Object | string) condition(Function) reduce(Object) initial(Array | Function) keyf(Function) finalize
  • removeProps?: (Bool) Flag to preserve property if the value is null or undefined.

Overloads:

None


indexOfAlt


Info: Array class extension to find index of a value based on a callback function & String class extension to find the index based on a regular expression

Return: (Integer)

Parameters:

  • value: (any) value to find
  • func: (ArrayIterator<T, TResult>) Callback function used to do the comparison

Overloads:

Parameters

  • regex: (RegExp) Regular expression to check value against
  • pos?: (Int) Index offset to start

innerJoin


Info: Array class extension to do an inner join on arrays

Return: (Array) resulting array of the join.

Parameters:

  • arr: (Array) Array to be joined with
  • on: (String) Condition to join on

Overloads:

None


insert


Info: Array class extension to add to the array

Return: (Bool)

Parameters:

  • value: (Mixed) value to add

Overloads:

None


insertAfter


Info: Array class extension to add to the array after a specific index

Return: (Bool) returns true for success and false for failure.

Parameters:

  • index: (Int) Index to add after
  • value: (any) Value to add

Overloads:

None


insertAt


Info: Array class extension to add to the array at a specific index and push the all indexes down

Return: (Bool) returns true for success and false for failure.

Parameters:

  • index: (Int) Index to add after
  • value: (any) Value to add

Overloads:

None


insertBefore


Info: Array class extension to add to the array before a specific index

Return: (Bool) returns true for success and false for failure.

Parameters:

  • index: (Int) Index to add before
  • value: (any) Value to add

Overloads:

None


joinLeft


Info: Array class extension to do an outer left join on arrays

Return: (Array) resulting array of the join.

Parameters:

  • arr: (Array) Secondary array to be joined with
  • on: (String) Condition to join on

Overloads:

None


joinRight


Info: Array class extension to do an outer right join on arrays

Return: (Array) resulting array of the join.

Parameters:

  • arr: (Array) Secondary array to be joined with
  • on: (String) Condition to join on

Overloads:

None


last


Info: Array class extension to retrieve the last item in the array.

Return: (T) returns the last item in the array.

Parameters:

None

Overloads:

None


limit


Info: Array class extension to return a limited amount of items

Return: (Array) returns the first n items in the array.

Parameters:

  • max: (Int) Maximum number of items to return
  • skip?: (Int) Number of items to skip

Overloads:

None


mapReduce


Info: Array class extension to run map-reduce aggregation over records

Return: (Array) returns the map reduced array.

Parameters:

  • map: (ArrayIterator<T, TResult>) Function to apply to each item
  • reduce: (MongoReducer) Function used to condense the items
  • options?: (MongoMapReduceOptions<T, TResult>) Options specified in the Mongo Doc

Overloads:

None


normalize


Info: Array class extension to normalize all properties in the object array

Return: (Array) returns a normalized version of the objects.

Parameters:

None

Overloads:

None


remove


Info: Array class extension to remove an item by value

Return: (T | undefined) returns the removed item.

Parameters:

  • value: (any) Value to remove
  • indexOf?: (ArrayIterator) Callback function to use to find the item based on the value

Overloads:

None


removeAll


Info: Array class extension to remove all items by value

Return: (Array) returns an array of all the removed items.

Parameters:

  • value?: (any) Value to remove
  • indexOf?: (IndexOf) Callback function to use to find the item based on the value

Overloads:

None


removeAt


Info: Array class extension to remove item at a specific index

Return: (T | undefined) returns the removed item.

Parameters:

  • index: (Int) Index of the item to remove

Overloads:

None


replaceAt


Info: Array class extension to replace item at a specific index

Return: (T | undefined) returns the item removed.

Parameters:

  • index: (Int) Index of the item to remove
  • value: (any) Value to replace with

Overloads:

None


scramble


Info: Array class extension to scramble the order.

Return: (Array)

Parameters:

None

Overloads:

None


sortBy


Info: Array class extension to sort the array

Return: (Array)

Parameters:

  • props: (string) Property/Comma delimited list of properties to sort by. If the first character is '!', the sort order is reversed

Overloads:

Parameters

  • props: (Array) Properties to sort by. If the first character is '!', the sort order is reversed

Parameters

  • props: (string) Property/Comma delimited list of properties to sort by. If the first character is '!', the sort order is reversed
  • rev: (Bool) Flag to reverse the sort

Parameters

  • props: (Array) Properties to sort by. If the first character is '!', the sort order is reversed
  • rev: (Bool) Flag to reverse the sort

Parameters

  • props: (string) Property/Comma delimited list of properties to sort by. If the first character is '!', the sort order is reversed
  • rev: (Bool) Flag to reverse the sort
  • primer: (SortPrimer|null|undefined) Function to apply to values in the array.

Parameters

  • props: (Array) Properties to sort by. If the first character is '!', the sort order is reversed
  • rev: (Bool) Flag to reverse the sort
  • primer: (SortPrimer|null|undefined) Function to apply to values in the array.

Parameters

  • props: (string) Property/Comma delimited list of properties to sort by. If the first character is '!', the sort order is reversed
  • rev: (Bool) Flag to reverse the sort
  • primer: (SortPrimer|null|undefined) Function to apply to values in the array.
  • lookup: (Object) Look up object to use as values instead of the array values.

Parameters

  • props: (Array) Properties to sort by. If the first character is '!', the sort order is reversed
  • rev: (Bool) Flag to reverse the sort
  • primer: (SortPrimer|null|undefined) Function to apply to values in the array.
  • lookup: (Object) Look up object to use as values instead of the array values.

Parameters

  • props: (string) Property/Comma delimited list of properties to sort by. If the first character is '!', the sort order is reversed
  • rev: (Bool) Flag to reverse the sort
  • primer: (SortPrimer|null|undefined) Function to apply to values in the array.
  • lookup: (Object) Look up object to use as values instead of the array values.
  • options: (Object) Options to pass. Valid options are:iignoreCase

Parameters

  • props: (Array) Properties to sort by. If the first character is '!', the sort order is reversed
  • rev: (Bool) Flag to reverse the sort
  • primer: (SortPrimer|null|undefined) Function to apply to values in the array.
  • lookup: (Object) Look up object to use as values instead of the array values.
  • options: (Object) Options to pass. Valid options are:iignoreCase

toMap


Info: Array class extension to convert the array to a set

Return: (Set) returns a Set from the array Values

Parameters:

None

Overloads:

None


toSet


Info: Array class extension to convert the array to a set

Return: (Set) returns a Set from the array Values

Parameters:

None

Overloads:

None


update


Info: Array class extension to update records in the array

Return: (Array)

Parameters:

  • condition: (WhereCondition) Query following find/where clause syntax
  • setClause: (MongoSet) Set clause used to update the records
  • options?: (UpdateOptions) Options to specify if mulit update and/or upsert

Overloads:

None


upsert


Info: Array class extension to upsert records to array

Return: (UpsertResult) returns the information for resulting operation.

Parameters:

  • records: (Array|T) Record(s) to use to insert/update array

Overloads:

Parameters

  • records: (Array|T) Records to use to insert/update array
  • callback: (UpsertIterator) Method to use to determine if the records are equal

Parameters

  • records: (Array|T) Records to use to insert/update array
  • prop: (string) Property to use as the primary key
  • callback?: (UpsertIterator) Method to use to determine if the records are equal

Download