JSPM

normalize-array-number

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q29075F
  • License MIT

normalize a numeric prop in an array between 0:100

Package Exports

  • normalize-array-number

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (normalize-array-number) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

normalize-array-number

normalize a numeric prop in an array between 0:100

Installation

npm install --save normalize-array-number

How it works

Given an array of objects, normalize a numeric property of each object between 0 and 100.

E.g.: [{n:2}, {n:4}, {n:0}] => [{n:50}, {n:100}, {n:0}]

You can customize min and max value, and you can optionally specify a number of decimal digits to round the values to. Array object are changed inplace.

Usage

  import normalize from 'normalize-array-number';
  const arr = [{n:2}, {n:4}, {n:0}];
  const result = normalize(arr, 'n');
  // result = [{n:50}, {n:100}, {n:0}]

API

normalize(arr, options)

  • arr: [REQUIRED] array of objects to normalize

  • options: [REQUIRED] either a string with the name of the property to normalize, or an object containing these properties:

    • prop: [REQUIRED] name of the property to normalize
    • min: value to assign to the minimum value encountered. Defaults to 0
    • max: value to assign to the maximum value encountered. Defaults to 100
    • round: number of decimal digits to round the values to, or false to avoid rounding. Defaults to false.

Return the same array received in input.

License

The MIT License (MIT) Copyright (c) 2015 Andrea Parodi