diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09a72c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/unset-value-1.0.0.tgz diff --git a/README.md b/README.md deleted file mode 100644 index 2bd7ee0..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# nodejs-unset-value - -'Delete nested properties from an object using dot notation' \ No newline at end of file diff --git a/nodejs-unset-value.spec b/nodejs-unset-value.spec new file mode 100644 index 0000000..9d1d7d6 --- /dev/null +++ b/nodejs-unset-value.spec @@ -0,0 +1,71 @@ +%{?nodejs_find_provides_and_requires} + +%global packagename unset-value +%global enable_tests 1 + +Name: nodejs-unset-value +Version: 1.0.0 +Release: 3%{?dist} +Summary: Delete nested properties from an object using dot notation + +License: MIT +URL: https://github.com/jonschlinkert/unset-value +Source0: https://registry.npmjs.org/%{packagename}/-/%{packagename}-%{version}.tgz +# The test files are not included in the npm tarball. +Source1: https://raw.githubusercontent.com/jonschlinkert/%{packagename}/%{version}/test.js + +ExclusiveArch: %{nodejs_arches} noarch +BuildArch: noarch + +BuildRequires: nodejs-packaging +BuildRequires: npm(has-value) +%if 0%{?enable_tests} +BuildRequires: mocha +BuildRequires: npm(should) +%endif + +%description +Delete nested properties from an object using dot notation. + + +%prep +%autosetup -n package +# setup the tests +cp -p %{SOURCE1} . + +%nodejs_fixdep isobject +%nodejs_fixdep has-value + +%build +# nothing to do! + +%install +mkdir -p %{buildroot}%{nodejs_sitelib}/%{packagename} +cp -pr package.json index.js \ + %{buildroot}%{nodejs_sitelib}/%{packagename} + +%nodejs_symlink_deps + +%check +%nodejs_symlink_deps --check +%{__nodejs} -e 'require("./")' +%if 0%{?enable_tests} +%{_bindir}/mocha -R spec +%else +%{_bindir}/echo -e "\e[101m -=#=- Tests disabled -=#=- \e[0m" +%endif + +%files +%doc README.md +%license LICENSE +%{nodejs_sitelib}/%{packagename} + +%changelog +* Fri Sep 15 2017 Jared Smith - 1.0.0-3 +- Relax dependency on npm(has-value) + +* Sat Apr 15 2017 Jared Smith - 1.0.0-2 +- Relax version of npm(isobject) + +* Fri Apr 14 2017 Jared Smith - 1.0.0-1 +- Initial packaging diff --git a/sources b/sources new file mode 100644 index 0000000..4a5a1f7 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (unset-value-1.0.0.tgz) = 3dc036b6cb86485f5c9f248b1d32d2876aab42227bd269feafe1a5cf1bf64d665b971b31082e76043959a0f0accfb49377da4dec465eb64599040be4e1c81975 diff --git a/test.js b/test.js new file mode 100644 index 0000000..ba7344a --- /dev/null +++ b/test.js @@ -0,0 +1,69 @@ +/*! + * unset + * + * Copyright (c) 2015 . + * Licensed under the MIT license. + */ + +'use strict'; + +/* deps: mocha */ +var assert = require('assert'); +var should = require('should'); +var unset = require('./'); + +describe('unset', function () { + it('should update the given object when a property is deleted:', function () { + var obj = {a: 'b'}; + unset(obj, 'a'); + obj.should.eql({}); + }); + + it('should return true when a property is deleted:', function () { + unset({a: 'b'}, 'a').should.eql(true); + }); + + it('should return true when the given property does not exist:', function () { + unset({a: 'b'}, 'z').should.eql(true); + }); + + it('should delete nested values:', function () { + var one = {a: {b: {c: 'd'}}}; + unset(one, 'a.b'); + one.should.eql({a: {}}); + + var two = {a: {b: {c: 'd'}}}; + unset(two, 'a.b.c'); + two.should.eql({a: {b: {}}}); + + var three = {a: {b: {c: 'd', e: 'f'}}}; + unset(three, 'a.b.c'); + three.should.eql({a: {b: {e: 'f'}}}); + }); + + it('should delete...:', function () { + var three = {'a.b': 'c', d: 'e'}; + unset(three, 'a.b'); + three.should.eql({d: 'e'}); + }); + + it('should delete nested escaped values:', function () { + var one = {a: {'b.c': 'd'}}; + unset(one, 'a.b\\.c'); + one.should.eql({a: {}}); + + var two = {'a.b.c': 'd'}; + unset(two, 'a\\.b\\.c'); + two.should.eql({}); + + var three = {'a.b': 'c', d: 'e'}; + unset(three, 'a\\.b'); + three.should.eql({d: 'e'}); + }); + + it('should throw an error when invalid args are passed:', function () { + (function () { + unset(); + }).should.throw('expected an object.'); + }); +});