@tsmx/human-readable
Advanced tools
Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "@tsmx/human-readable", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Easily create human-readable strings from byte sizes, e.g. 17238 --> 17.24 kB. Supports decimal (MB,GB,..) and binary (MiB, GiB,..) units as well as user-defined conversion from/to other sizes.", | ||
@@ -33,4 +33,4 @@ "main": "human-readable.js", | ||
"devDependencies": { | ||
"jest": "^26.4.2" | ||
"jest": "^27.2.0" | ||
} | ||
} |
@@ -6,3 +6,3 @@ # [**@tsmx/human-readable**](https://github.com/tsmx/human-readable) | ||
![node-current (scoped)](https://img.shields.io/node/v/@tsmx/human-readable) | ||
[![Build Status](https://img.shields.io/github/workflow/status/tsmx/human-readable/git-ci-build)](https://img.shields.io/github/workflow/status/tsmx/human-readable/git-ci-build) | ||
[![Build Status](https://img.shields.io/github/actions/workflow/status/tsmx/human-readable/git-build.yml?branch=master)](https://img.shields.io/github/actions/workflow/status/tsmx/human-readable/git-build.yml?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/github/tsmx/human-readable/badge.svg?branch=master)](https://coveralls.io/github/tsmx/human-readable?branch=master) | ||
@@ -14,3 +14,3 @@ | ||
Also check out the [full documentation](https://tsmx.net/human-readable/). | ||
Also check out the [full documentation](https://tsmx.net/human-readable/). If you need to use this package on the client-side in the browser, refer to [this article](https://tsmx.net/npm-packages-browser/). | ||
@@ -17,0 +17,0 @@ ## Usage |
describe('human-readable conversion test suite for decimal and IEC units', () => { | ||
it('tests a successful automatic conversion to bytes', async (done) => { | ||
it('tests a successful automatic conversion to bytes', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(999)).toBe('999 B'); | ||
expect(hr.fromBytes(999, { mode: 'IEC' })).toBe('999 B'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to kilo-bytes', async (done) => { | ||
it('tests a successful automatic conversion to kilo-bytes', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(58000)).toBe('58 kB'); | ||
expect(hr.fromBytes(58000, { mode: 'IEC' })).toBe('56.64 KiB'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to mega-bytes', async (done) => { | ||
it('tests a successful automatic conversion to mega-bytes', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(35899650)).toBe('35.90 MB'); | ||
expect(hr.fromBytes(35899650, { mode: 'IEC' })).toBe('34.24 MiB'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to giga-bytes', async (done) => { | ||
it('tests a successful automatic conversion to giga-bytes', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(17535899650)).toBe('17.54 GB'); | ||
expect(hr.fromBytes(17535899650, { mode: 'IEC' })).toBe('16.33 GiB'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to terra-bytes', async (done) => { | ||
it('tests a successful automatic conversion to terra-bytes', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(6917535899650)).toBe('6.92 TB'); | ||
expect(hr.fromBytes(6917535899650, { mode: 'IEC' })).toBe('6.29 TiB'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to peta-bytes', async (done) => { | ||
it('tests a successful automatic conversion to peta-bytes', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(179336917535899650)).toBe('179.34 PB'); | ||
expect(hr.fromBytes(179336917535899650, { mode: 'IEC' })).toBe('159.28 PiB'); | ||
done(); | ||
}); | ||
it('tests a successful conversion from kilo-bytes to mega-bytes', async (done) => { | ||
it('tests a successful conversion from kilo-bytes to mega-bytes', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromTo(999, 'KBYTE', 'MBYTE')).toBe('1.00 MB'); | ||
expect(hr.fromTo(999, 'KBYTE', 'MBYTE', { mode: 'IEC' })).toBe('0.98 MiB'); | ||
done(); | ||
}); | ||
it('tests a successful conversion from giga-bytes to kilo-bytes', async (done) => { | ||
it('tests a successful conversion from giga-bytes to kilo-bytes', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromTo(17.34, 'GBYTE', 'KBYTE')).toBe('17340000 kB'); | ||
expect(hr.fromTo(17.34, 'GBYTE', 'KBYTE', { mode: 'IEC' })).toBe('18182307.84 KiB'); | ||
done(); | ||
}); | ||
it('tests a successful conversion from kilo-byte to kilo-byte', async (done) => { | ||
it('tests a successful conversion from kilo-byte to kilo-byte', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromTo(17.34, 'KBYTE', 'KBYTE')).toBe('17.34 kB'); | ||
expect(hr.fromTo(17.34, 'KBYTE', 'KBYTE', { mode: 'IEC' })).toBe('17.34 KiB'); | ||
done(); | ||
}); | ||
it('tests a failed conversion with unknown sizes', async (done) => { | ||
it('tests a failed conversion with unknown sizes', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromTo(17.34, 'XBYTE', 'XBYTE')).toMatch(/NaN.*/); | ||
expect(hr.fromTo(17.34, 'XBYTE', 'XBYTE', { mode: 'IEC' })).toMatch(/NaN.*/); | ||
done(); | ||
}); | ||
it('tests the retrieval of available sizes', async (done) => { | ||
it('tests the retrieval of available sizes', async () => { | ||
const hr = require('../human-readable'); | ||
@@ -84,5 +74,4 @@ sizes = hr.availableSizes(); | ||
expect(sizes[5]).toBe('PBYTE'); | ||
done(); | ||
}); | ||
}); |
describe('human-readable options test suite', () => { | ||
it('tests a successful automatic conversion to mega-bytes - options: none', async (done) => { | ||
it('tests a successful automatic conversion to mega-bytes - options: none', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(35899650)).toBe('35.90 MB'); | ||
expect(hr.fromBytes(35899650, { mode: 'IEC' })).toBe('34.24 MiB'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to mega-bytes - options: number-only', async (done) => { | ||
it('tests a successful automatic conversion to mega-bytes - options: number-only', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(35899650, { numberOnly: true })).toBe('35.90'); | ||
expect(hr.fromBytes(35899650, { mode: 'IEC', numberOnly: true })).toBe('34.24'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to mega-bytes - options: no-whitespace', async (done) => { | ||
it('tests a successful automatic conversion to mega-bytes - options: no-whitespace', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(35899650, { noWhitespace: true })).toBe('35.90MB'); | ||
expect(hr.fromBytes(35899650, { mode: 'IEC', noWhitespace: true })).toBe('34.24MiB'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to mega-bytes - options: number-only overriding no-whitespace', async (done) => { | ||
it('tests a successful automatic conversion to mega-bytes - options: number-only overriding no-whitespace', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(35899650, { numberOnly: true, noWhitespace: true })).toBe('35.90'); | ||
expect(hr.fromBytes(35899650, { mode: 'IEC', numberOnly: true, noWhitespace: true })).toBe('34.24'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to mega-bytes - options: full-precision', async (done) => { | ||
it('tests a successful automatic conversion to mega-bytes - options: full-precision', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(35899650, { fullPrecision: true })).toBe('35.89965 MB'); | ||
expect(hr.fromBytes(35899650, { mode: 'IEC', fullPrecision: true })).toBe('34.23657417297363 MiB'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to mega-bytes - options: fixed-precision = 3', async (done) => { | ||
it('tests a successful automatic conversion to mega-bytes - options: fixed-precision = 3', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(35899650, { fixedPrecision: 3 })).toBe('35.900 MB'); | ||
expect(hr.fromBytes(35899650, { mode: 'IEC', fixedPrecision: 3 })).toBe('34.237 MiB'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to mega-bytes - options: fixed-precision NaN, ignored', async (done) => { | ||
it('tests a successful automatic conversion to mega-bytes - options: fixed-precision NaN, ignored', async () => { | ||
const hr = require('../human-readable'); | ||
@@ -50,26 +44,22 @@ expect(hr.fromBytes(35899650, { fixedPrecision: 'ttt' })).toBe('35.90 MB'); | ||
expect(hr.fromBytes(35899650, { mode: 'IEC', fixedPrecision: 'ttt' })).toBe('34.24 MiB'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to mega-bytes - options: fixed-precision = 0', async (done) => { | ||
it('tests a successful automatic conversion to mega-bytes - options: fixed-precision = 0', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(35899650, { fixedPrecision: 0 })).toBe('36 MB'); | ||
expect(hr.fromBytes(35899650, { mode: 'IEC', fixedPrecision: 0 })).toBe('34 MiB'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to mega-bytes - options: full-precision overriding fixed-precision', async (done) => { | ||
it('tests a successful automatic conversion to mega-bytes - options: full-precision overriding fixed-precision', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(35899650, { fullPrecision: true, fixedPrecision: 3 })).toBe('35.89965 MB'); | ||
expect(hr.fromBytes(35899650, { mode: 'IEC', fullPrecision: true, fixedPrecision: 3 })).toBe('34.23657417297363 MiB'); | ||
done(); | ||
}); | ||
it('tests a successful automatic conversion to mega-bytes - options: full-precision, number-only overriding fixed-precision and no-whitespace', async (done) => { | ||
it('tests a successful automatic conversion to mega-bytes - options: full-precision, number-only overriding fixed-precision and no-whitespace', async () => { | ||
const hr = require('../human-readable'); | ||
expect(hr.fromBytes(35899650, { fullPrecision: true, fixedPrecision: 3, numberOnly: true, noWhitespace: true })).toBe('35.89965'); | ||
expect(hr.fromBytes(35899650, { mode: 'IEC', fullPrecision: true, fixedPrecision: 3, numberOnly: true, noWhitespace: true })).toBe('34.23657417297363'); | ||
done(); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18386
289