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

svz-number-manager

v1.0.2

Published

A utility for managing Numbers with a variety of use cases.

Downloads

4

Readme

svz-number-manager

This module provides four management classes for manipulating Numbers for multiple use cases I've employed on a number of occasions, including formatting currencies, phone numbers, manipulating and standardizing number of digits, and determining decimal places as specified or from existing numbers. In the future, this will incorporate currency conversions.

Installation

To install, in terminal type

	npm i --save svz-number-manager

then, in your project,

import NumberManager from 'svz-number-manager';

NumberManager

Format: numMan = new NumberManager(num, {country, currencyStyle, max, min, phoneStyle, size}) Manipulates a supplied Number or String of numeric characters which may include one . character as needed for a variety of use cases. Using a Number variable produces a different set of behaviors from using a String, so making sure you're using the right type is important, here.

Class Variables

  • countries
    READ-ONLY
    This is a list of the styling defaults for each country in a format shown here for the United States.

US: { currency: { code: 'USD', format: "$*.##" }, phone: "(###) ###-####" }

  • country
    Type: String
    Default: US
    Note: This is more of a placeholder at the moment, as only US is implemented. Later, more will be added. This value dictates the defaults for styling based on your country.

  • currencyStyle
    Type: String
    Default: this.countries[this.country].currency.format || $*:##
    This determines the default style for the toCurrency function.

  • max
    Type: Number
    This determines the maximum numerical limit of the returned Number or String

  • min
    Type: Number
    This determines the minimum numerical limit of the returned Number or String

  • num
    Type: Number || String
    The default value used as a number. Automatically restricts by min and max, and applies setSize

  • phoneStyle
    Type: String
    Default: this.countries[this.country].phone || (###) ###-####
    This determines the default style for the toPhone function.

  • size
    Type: Number || String
    The number of decimal spaces or length of the number (depending on whether String or Number is used in the function).
    Note: when using a String, set Behavior changes from simply the number itself to using that string to determine it. If a . character is found in the string, size is the number of decimal places in the String number. If no . character is found, size is the overall length of the String. Be conscious of this methodology, because if you want to include a . character, but are not attempting to find the decimal places, you will have to set size using a Number, instead. This functionality is included so that a value can be used as a "template" for determining size for NumberManager.

Methods

absRound(num, direction, size)

  • num
    Type: Number || String
    Default: this.num
    The target of the function.

  • direction
    Type: String
    Valid Values: floor || ceil
    Default: ceil
    If floor is used, it rounds towards 0. If ceil is used, it rounds away from 0.

  • absolute
    Type: Boolean
    If absolute is set to true, the value is returned as always positive.

calcAdditive (num, increment, max, init)

  • num
    Type: Number || String
    Default: this.num
    The target of the function.

  • increment
    Type: Number
    Default: 1
    The amount of incremental growth with each iteration.

  • max
    Type: Number
    The maximum size of the incremental growth. If the incremental growth would exceed this value, max is used instead.

  • init
    Type: Number
    Default: 0
    The initial amount the increment begins at (not including.

confine(num, max, min)

  • num
    Type: Number || String
    Default: this.num
    The target of the function.

  • max
    Type: Number
    Default: this.max
    The maximum limit.

  • min
    Type: Number
    Default: this.min
    The minimum limit.

decimalPlaces(num)

  • num
    Type: Number || String
    Default: this.num
    The target of the function.

positive(num, asDirection)

  • num
    Type: Number || String
    Default: this.num
    The target of the function.

  • asDirection
    Type: Boolean
    If asDirection is set to true, positive instead returns 1 for a positive number and -1 for a negative number. If it is false, it returns true for a positive number and false for a negative number.

rand(max, min)

  • max
    Type: Number
    Default: this.max || 99
    The maximum value for the returnved value. Inclusive.

  • min
    Type: Number
    Default: this.min || 0
    The minimum value for the returned value. Inclusive.

setSize(num, size)

  • num
    Type: Number || String
    Default: this.num
    The target of the function.

  • size
    Type: Number
    Default: this.size
    If num is a String, this adds prefix zeroes until it is size length. If num is a Number, it fixes the decimal places to size.

toCurrency(num, style)

  • num
    Type: Number || String
    Default: this.num
    The target of the function.

  • style
    Type: String
    Default: this.currencyStyle
    This dictates the formatting of the number, using * to mean either all digits before the decimal or all digits following the decimal, and # to signify individual numbers.

toPhone(num, style)

  • num
    Type: Number
    Default: this.num
    The number being used as the target of the function

  • style
    Type: String
    Default: this.phoneStyle
    This dictates the formatting of the number, using # where the digits should be inserted.

Author

Version History

1.0.0 - Initial Release.