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

@cowrie/cowrie

v1.1.2

Published

Cowrie is a JavaScript utility that allows you to add, subtract, multiply, divide, sort & partition monetary values

Downloads

9

Readme

Cowrie

Cowrie is a JavaScript utility that allows you to add, subtract, multiply, divide, sort & partition monetary values

Installation

Cowrie requires Node.js v10+ to run.

$ npm install --save @cowrie/cowrie

Usage

Cowrie can be used both in a Node.js environment (server-side) or in a browser environment (client-side). After the installation with npm, add it to your source files using either of the following:

1. ES6 import statement

import Cowrie from "@cowrie/cowrie";

2. Commonjs require statement

const Cowrie = require('@cowrie/cowrie');

The following are methods available in the Cowrie object, which also amount to its features. These are some a few things to note when using the utility.

The results of the plus(), minus(), times(), and divide methods is another Cowrie instance. The allocate() method however, returns an array of Cowrie instances. Use the figure property to retrieve a string representation of the monetary value figure, without the currency.

For addition (+) and subtraction (−), the numbers are assumbed to be of the same currency instantiated.

The allocate() method takes a array of numbers that represent a ratio, with 100% as a whole.

Features

+ Addition

const a = new Cowrie('KES', 0).plus(2).figure;
const b = new Cowrie('KES', 0).plus(0.1, 0.2).figure;
const c = new Cowrie('KES', 0).plus(...[1.1, 1.1, 1.1, 4]).figure;

console.log({a, b, c});

− Subtraction

const a = new Cowrie('KES', 0).minus(2).figure;
const b = new Cowrie('KES', 0).minus(0.1, 0.2).figure;
const c = new Cowrie('KES', 0).minus(...[1.1, 1.1, 1.1, 4]).figure;

console.log({a, b, c});

× Multiplication

const a = new Cowrie('KES', 2090.5).times(8.61).figure;
const b = new Cowrie('KES', 2090.5, 3).times(8.61).figure;
const c = new Cowrie('KES', 209050).times(8.61).figure;

console.log({a, b, c});

÷ Division

const a = new Cowrie('KES', 1.21).divide(0.1).figure;
const b = new Cowrie('KES', 0.2).divide(0.1).figure;
const c = new Cowrie('KES', 0.2).divide(3).figure;
const d = new Cowrie('KES', 0.3).divide(3).figure;

console.log({a, b, c, d});

a : b : c Allocation

const a = new Cowrie('KES', 500).allocate([3, 2]).map(x => x.figure);
const b = new Cowrie('KES', 500).allocate([1, 1, 1]).map(x => x.figure);
const c = new Cowrie('KES', 500).allocate([0, 1, 1]).map(x => x.figure);

console.log({a, b, c, d});

Comma separators

const a = new Cowrie('KES', 0, 0, true);
const b = new Cowrie('KES', 0.123456, 6,true );

const c = new Cowrie('KES', 100, 0, true );
const d = new Cowrie('KES', 100.123456, 6,true );

const e = new Cowrie('KES', 1000, 0,true );
const f = new Cowrie('KES', 1000.123456, 6, true );

const g = new Cowrie('KES', 10000, 0,true );
const h = new Cowrie('KES', 10000.123456, 6,true );

const i = new Cowrie('KES', 100000, 0,true );
const j = new Cowrie('KES', 100000.123456, 6,true );

const k = new Cowrie('KES', 1000000, 0, true );
const l = new Cowrie('KES', 1000000.123456, 6,true );

const m = new Cowrie('KES', 10000000, 0,true);
const n = new Cowrie('KES', 10000000.123456, 6,true );

console.log({a, b, c, d, e, f, g, h, i, j, k, l, m, n})

License

MIT