package init
This commit is contained in:
parent
962b77b210
commit
4cf917ac74
53
nodejs-pretty-bytes.spec
Normal file
53
nodejs-pretty-bytes.spec
Normal file
@ -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 <wangchong56@huawei.com> - 4.0.2-1
|
||||
- package init
|
||||
4
nodejs-pretty-bytes.yaml
Normal file
4
nodejs-pretty-bytes.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
version-control: github
|
||||
src_repo: sindresorhus/pretty-bytes
|
||||
tag_prefix: ^v
|
||||
seperator: .
|
||||
BIN
pretty-bytes-4.0.2.tgz
Normal file
BIN
pretty-bytes-4.0.2.tgz
Normal file
Binary file not shown.
33
test.js
Normal file
33
test.js
Normal file
@ -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');
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user