
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@flourish/enhanced-arrays
Advanced tools
The purpose of this module is to make working with collections of data of a single type (string, numeric, datetime) simpler. Each "enhanced array" is an immutable object which is created with a fixed set of values. The properties and methods on the array object then give the user easy access to properties, subsets and transformations of the data without the need for them to draw in additional libraries.
npm install @flourish/enhanced-arrays;
Import the relevant creater functions from the module...
import {
createNumericArray, createDatetimeArray, createStringArray
} from @flourish/enhanced-arrays;
then create an enhanced array object by calling them with aregular array of data of the relevant type.
const dates = [new Date(2022-02-02), new Date(2022-02-02), new Date(2023-02-01)];
const numbers = createNumericArray([1, 5, 6, 4, 8, 5]);
const strings = createStringArray('a', "boat", "21", "boat");
const dates = createDatetimeArray(dates);
You can also call supply an accessor function to extract or transform transform the data from the input area:
const things = [{x: "coats", y: 7}, {x: "hats", y: 10}, {x: "boots", y: 6} ];
const more_numbers = createNumericArray(things, d => d.y);
Any element passed to a creater function that is of the wrong type (after the accessor function is applied, if used) will be rejected. These values will not be used in any calculations and there values will not be stored in the enhanced arrays. However, their indexes from the original input array will still be available through a dropped_indexes property that returns a frozen array of these indexes.
const other_things = [{x: "cat", y: 5}, {x: "dog", y: 4}, {x: "mouse", y: "two"} ];
const yet_more_numbers = createNumericArray(other_things, d => d.y);
console.log(yet_more_things.dropped_indexes); // [2];
datetime_arraytrue for datetime arrays. undefined for numeric and string arrays.
dropped_indexesThe indexes of all values from the input array (or the array created after running the accessor function on the input array) that were dropped because they were of the wrong type.
enhanced_arraytrue for all enhanced arrays.
lengthThe number of values in the stored array. This is the length of the input array minus the number of values that were rejected for being of the wrong type.
maxThe largest value in a numeric array, the latest timestamp in a datetime array and the last string alphabetically in a string array.
meanThe (arithmetic) mean value in a numeric or datetime array. undefined for a string array.
medianThe median value in a numeric or datetime array. undefined for a string array.
minThe smallest value in a numeric array, the earliest timestamp in a datetime array and the first string alphabetically in a string array.
n_emptyThe number of empty string ("") in a string array. undefined for numeric and datetime arrays.
numeric_arraytrue for all numeric arrays. undefined for datetime and string arrrays.
rangeThe difference between the max and in min values in a numeric array. undefined for datetime and string arrays.
sdThe (sample) standard deviation of the values in a numeric array. undefined for datetime and string arrays.
sorted_valuesA frozen array of all values stored in the enhanced array, in ascending order. For numeric arrays this means numeric sorting (eg 2 before 10), for string arrays this means alphabetical/lexical sorting (eg "10" before "2" but after "1") and for datetimes that means the earliest date appears first.
sumThe sum of all entries in a numeric array. undefined for datetime and string arrays.
string_arraytrue for all string arrays. undefined for all numeric and datetime arrays.
valuesA frozen array of all values stored in the enhanced array following the order of the input array.
varianceThe (sample) variance of the values in a numeric array. undefined for datetime and string arrays.
ascending()Returns an array of the stored values, sorted in ascending order. The result of calling this method is different from the sorted_values property in that the array returned is a not frozen and can be altered.
descending()Returns an array of the stored values, sorted in descending order.
extent()Returns a two-element array describing the extent of the data, ie [min, max].
rank([lowest_first [, ties_method])Returns a map of the stored values to their rank as outlined in the arguments to the funciton call. By default values will be ranked largest to smallest (numeric), last to first (datetime) or latest alphabetically to earliest alphabetically (string). If lowest_first is truthy then then this ranking system will be reversed. The ties_method determines the rank in the case of ties. Recognised values are "best" (default), "worst", "dense", "fractional" and "ordinal". In the "best" case tied entries will share the lower-numbered rank (representation 1 2 2 4, assuming a tie for 2nd rank). In the "worst" case tied entries will share the higher-numbered rank (1 3 3 4). In the "dense" case tied entries will share the lower rank with the next highest ranking value taking the rank 1 above that (1 2 2 3). In the "fractional" case the possible ranks are averaged (1 2.5 2.5 4). In the "ordinal" case the tie values are arbitrairily given different ranks despite the tie (1 2 3 4). See also this Wikipedia article.
unique()Returns an array of the stored values with duplicates removed. For datetimes, timestamps are used to determine if two-different entries are duplicates.
uniqueAscending()Returns an array of the stored values, sorted in ascending order, with duplicates removed. For datetimes, timestamps are used to determine if two-different entries are duplicates.
uniqueDescending()Returns an array of the stored values, sorted in ascending order, with duplicates removed. For datetimes, timestamps are used to determine if two-different entries are duplicates.
unsorted()Returns an array of the stored values. The result of calling this method is different from the values property in that the array returned is a not frozen and can be altered.
FAQs
Create immutable array-like-objects with useful methods
We found that @flourish/enhanced-arrays demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 33 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.