@flourish/enhanced-arrays

中文文档
2.0.0发布于 2022/02/11https://flourish.studio/terms/fcl/ESM + CJS近 30 天下载 3820

Create immutable array-like-objects with useful methods

原始使用文档
文档目录29 节
  1. How to install
  2. How to create an enhanced array
  3. Properties of enhanced arrays
  4. datetime_array
  5. dropped_indexes
  6. enhanced_array
  7. length
  8. max
  9. mean
  10. median
  11. min
  12. n_empty
  13. numeric_array
  14. range
  15. sd
  16. sorted_values
  17. sum
  18. string_array
  19. values
  20. variance
  21. Methods of enhanced arrays
  22. ascending()
  23. descending()
  24. extent()
  25. rank([lowest_first [, ties_method])
  26. unique()
  27. uniqueAscending()
  28. uniqueDescending()
  29. unsorted()

Flourish enhaced arrays

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.

How to install

npm install @flourish/enhanced-arrays;

How to create an enhanced array

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];

Properties of enhanced arrays

datetime_array

true for datetime arrays. undefined for numeric and string arrays.

dropped_indexes

The 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_array

true for all enhanced arrays.

length

The 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.

max

The largest value in a numeric array, the latest timestamp in a datetime array and the last string alphabetically in a string array.

mean

The (arithmetic) mean value in a numeric or datetime array. undefined for a string array.

median

The median value in a numeric or datetime array. undefined for a string array.

min

The smallest value in a numeric array, the earliest timestamp in a datetime array and the first string alphabetically in a string array.

n_empty

The number of empty string ("") in a string array. undefined for numeric and datetime arrays.

numeric_array

true for all numeric arrays. undefined for datetime and string arrrays.

range

The difference between the max and in min values in a numeric array. undefined for datetime and string arrays.

sd

The (sample) standard deviation of the values in a numeric array. undefined for datetime and string arrays.

sorted_values

A 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.

sum

The sum of all entries in a numeric array. undefined for datetime and string arrays.

string_array

true for all string arrays. undefined for all numeric and datetime arrays.

values

A frozen array of all values stored in the enhanced array following the order of the input array.

variance

The (sample) variance of the values in a numeric array. undefined for datetime and string arrays.

Methods of enhanced 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.

版本与发布记录

@flourish/enhanced-arrays 共发布 7 个版本,首次发布于 2019/06/26;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.0latest2022/02/114 年前
1.1.12021/06/255 年前
1.1.02019/10/267 年前
1.1.0-prerelease.1next2019/10/257 年前
1.0.02019/08/167 年前
1.0.0-prerelease.22019/06/277 年前

关于 @flourish/enhanced-arrays 的常见问题

@flourish/enhanced-arrays 是什么?

Create immutable array-like-objects with useful methods

如何安装 @flourish/enhanced-arrays?

在项目目录运行 npm install @flourish/enhanced-arrays,或使用 pnpm add / yarn add / bun add。

@flourish/enhanced-arrays 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/flourish__enhanced-arrays 是否存在。

@flourish/enhanced-arrays 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flourish/enhanced-arrays 可以商用吗?

@flourish/enhanced-arrays 使用 https://flourish.studio/terms/fcl/ 许可。声明的许可为 https://flourish.studio/terms/fcl/,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@flourish/enhanced-arrays 的下载量有多少?

根据 npm 官方下载统计,@flourish/enhanced-arrays 在 2026/10/15 – 2026/11/13 这 30 天内被下载 3,820 次,日均约 127 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flourish/enhanced-arrays 还在维护吗?

最新版本 2.0.0 发布于 2022/02/11(4 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/06/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。