diff --git a/nodejs-pretty-bytes.spec b/nodejs-pretty-bytes.spec new file mode 100644 index 0000000..02d5fb3 --- /dev/null +++ b/nodejs-pretty-bytes.spec @@ -0,0 +1,53 @@ +%{?nodejs_find_provides_and_requires} +%global enable_tests 0 +Name: nodejs-pretty-bytes +Version: 4.0.2 +Release: 1 +Summary: Convert bytes to a human readable string +License: MIT +URL: https://github.com/sindresorhus/pretty-bytes +Source0: http://registry.npmjs.org/pretty-bytes/-/pretty-bytes-%{version}.tgz +Source1: https://raw.githubusercontent.com/sindresorhus/pretty-bytes/v%{version}/test.js +BuildArch: noarch +ExclusiveArch: %{nodejs_arches} noarch +BuildRequires: nodejs-packaging +%if 0%{?enable_tests} +BuildRequires: npm(ava) +%endif +%description +%{summary}. + +%prep +%setup -q -n package +cp -p %{SOURCE1} . + +%build + +%install +mkdir -p %{buildroot}%{nodejs_sitelib}/pretty-bytes +cp -pr package.json *.js \ + %{buildroot}%{nodejs_sitelib}/pretty-bytes +mkdir -p %{buildroot}%{_bindir} +ln -sf %{nodejs_sitelib}/pretty-bytes/cli.js \ + %{buildroot}%{_bindir}/pretty-bytes +%nodejs_symlink_deps + +%check +%nodejs_symlink_deps --check +%{__nodejs} -e 'require("./")' +%if 0%{?enable_tests} +%{_bindir}/ava +%else +%{_bindir}/echo -e "\e[101m -=#=- Tests disabled -=#=- \e[0m" +%endif + +%files +%{!?_licensedir:%global license %doc} +%license license +%doc readme.md +%{nodejs_sitelib}/pretty-bytes +%{_bindir}/pretty-bytes + +%changelog +* Thu Aug 20 2020 wangchong - 4.0.2-1 +- package init diff --git a/nodejs-pretty-bytes.yaml b/nodejs-pretty-bytes.yaml new file mode 100644 index 0000000..9dcfd2d --- /dev/null +++ b/nodejs-pretty-bytes.yaml @@ -0,0 +1,4 @@ +version-control: github +src_repo: sindresorhus/pretty-bytes +tag_prefix: ^v +seperator: . diff --git a/pretty-bytes-4.0.2.tgz b/pretty-bytes-4.0.2.tgz new file mode 100644 index 0000000..95ccc2b Binary files /dev/null and b/pretty-bytes-4.0.2.tgz differ diff --git a/test.js b/test.js new file mode 100644 index 0000000..c3d7f03 --- /dev/null +++ b/test.js @@ -0,0 +1,33 @@ +import test from 'ava'; +import m from './'; + +test('throws on invalid input', t => { + t.throws(() => m('')); + t.throws(() => m('1')); + t.throws(() => m(NaN)); + t.throws(() => m(true)); + t.throws(() => m(Infinity)); + t.throws(() => m(-Infinity)); + t.throws(() => m(null)); +}); + +test('converts bytes to human readable strings', t => { + t.is(m(0), '0 B'); + t.is(m(0.4), '0.4 B'); + t.is(m(0.7), '0.7 B'); + t.is(m(10), '10 B'); + t.is(m(10.1), '10.1 B'); + t.is(m(999), '999 B'); + t.is(m(1001), '1 kB'); + t.is(m(1001), '1 kB'); + t.is(m(1e16), '10 PB'); + t.is(m(1e30), '1000000 YB'); +}); + +test('supports negative number', t => { + t.is(m(-0.4), '-0.4 B'); + t.is(m(-0.7), '-0.7 B'); + t.is(m(-10.1), '-10.1 B'); + t.is(m(-999), '-999 B'); + t.is(m(-1001), '-1 kB'); +});