pax_global_header00006660000000000000000000000064131001620370014503gustar00rootroot0000000000000052 comment=9c2ebcb48968ab3cd1e5ebe84b55b6c926a2a3e8 object.defaults-1.1.0/000077500000000000000000000000001310016203700145565ustar00rootroot00000000000000object.defaults-1.1.0/.editorconfig000066400000000000000000000004051310016203700172320ustar00rootroot00000000000000root = true [*] indent_style = space end_of_line = lf charset = utf-8 indent_size = 2 trim_trailing_whitespace = true insert_final_newline = true [{**/{actual,fixtures,expected,templates}/**,*.md}] trim_trailing_whitespace = false insert_final_newline = falseobject.defaults-1.1.0/.eslintrc.json000066400000000000000000000071251310016203700173570ustar00rootroot00000000000000{ "ecmaFeatures": { "modules": true, "experimentalObjectRestSpread": true }, "env": { "browser": false, "es6": true, "node": true, "mocha": true }, "globals": { "document": false, "navigator": false, "window": false }, "rules": { "accessor-pairs": 2, "arrow-spacing": [2, { "before": true, "after": true }], "block-spacing": [2, "always"], "brace-style": [2, "1tbs", { "allowSingleLine": true }], "comma-dangle": [2, "never"], "comma-spacing": [2, { "before": false, "after": true }], "comma-style": [2, "last"], "constructor-super": 2, "curly": [2, "multi-line"], "dot-location": [2, "property"], "eol-last": 2, "eqeqeq": [2, "allow-null"], "generator-star-spacing": [2, { "before": true, "after": true }], "handle-callback-err": [2, "^(err|error)$" ], "indent": [2, 2, { "SwitchCase": 1 }], "key-spacing": [2, { "beforeColon": false, "afterColon": true }], "keyword-spacing": [2, { "before": true, "after": true }], "new-cap": [2, { "newIsCap": true, "capIsNew": false }], "new-parens": 2, "no-array-constructor": 2, "no-caller": 2, "no-class-assign": 2, "no-cond-assign": 2, "no-const-assign": 2, "no-control-regex": 2, "no-debugger": 2, "no-delete-var": 2, "no-dupe-args": 2, "no-dupe-class-members": 2, "no-dupe-keys": 2, "no-duplicate-case": 2, "no-empty-character-class": 2, "no-eval": 2, "no-ex-assign": 2, "no-extend-native": 2, "no-extra-bind": 2, "no-extra-boolean-cast": 2, "no-extra-parens": [2, "functions"], "no-fallthrough": 2, "no-floating-decimal": 2, "no-func-assign": 2, "no-implied-eval": 2, "no-inner-declarations": [2, "functions"], "no-invalid-regexp": 2, "no-irregular-whitespace": 2, "no-iterator": 2, "no-label-var": 2, "no-labels": 2, "no-lone-blocks": 2, "no-mixed-spaces-and-tabs": 2, "no-multi-spaces": 2, "no-multi-str": 2, "no-multiple-empty-lines": [2, { "max": 1 }], "no-native-reassign": 0, "no-negated-in-lhs": 2, "no-new": 2, "no-new-func": 2, "no-new-object": 2, "no-new-require": 2, "no-new-wrappers": 2, "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, "no-proto": 0, "no-redeclare": 2, "no-regex-spaces": 2, "no-return-assign": 2, "no-self-compare": 2, "no-sequences": 2, "no-shadow-restricted-names": 2, "no-spaced-func": 2, "no-sparse-arrays": 2, "no-this-before-super": 2, "no-throw-literal": 2, "no-trailing-spaces": 0, "no-undef": 2, "no-undef-init": 2, "no-unexpected-multiline": 2, "no-unneeded-ternary": [2, { "defaultAssignment": false }], "no-unreachable": 2, "no-unused-vars": [2, { "vars": "all", "args": "none" }], "no-useless-call": 0, "no-with": 2, "one-var": [0, { "initialized": "never" }], "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], "padded-blocks": [0, "never"], "quotes": [2, "single", "avoid-escape"], "radix": 2, "semi": [2, "always"], "semi-spacing": [2, { "before": false, "after": true }], "space-before-blocks": [2, "always"], "space-before-function-paren": [2, "never"], "space-in-parens": [2, "never"], "space-infix-ops": 2, "space-unary-ops": [2, { "words": true, "nonwords": false }], "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], "use-isnan": 2, "valid-typeof": 2, "wrap-iife": [2, "any"], "yoda": [2, "never"] } } object.defaults-1.1.0/.gitattributes000066400000000000000000000001771310016203700174560ustar00rootroot00000000000000# Enforce Unix newlines * text eol=lf # binaries *.ai binary *.psd binary *.jpg binary *.gif binary *.png binary *.jpeg binaryobject.defaults-1.1.0/.gitignore000066400000000000000000000004171310016203700165500ustar00rootroot00000000000000# always ignore files *.DS_Store *.sublime-* # test related, or directories generated by tests test/actual actual coverage .nyc* # npm node_modules npm-debug.log # yarn yarn.lock yarn-error.log # misc _gh_pages _draft _drafts bower_components vendor temp tmp TODO.md object.defaults-1.1.0/.travis.yml000066400000000000000000000002001310016203700166570ustar00rootroot00000000000000sudo: false language: node_js node_js: - node - iojs - '7' - '6' - '5' - '4' - '0.12' - '0.10' git: depth: 10 object.defaults-1.1.0/.verb.md000066400000000000000000000006201310016203700161120ustar00rootroot00000000000000{%= include("install-bower", {save: true}) %} ## Usage ```js var defaults = require('{%= name %}'); var obj = {a: 'c'}; defaults(obj, {a: 'bbb', d: 'c'}); console.log(obj); //=> {a: 'c', d: 'c'} ``` Or immutable defaulting: ```js var defaults = require('{%= name %}/immutable'); var obj = {a: 'c'}; var defaulted = defaults(obj, {a: 'bbb', d: 'c'}); console.log(obj !== defaulted); //=> true ``` object.defaults-1.1.0/LICENSE000066400000000000000000000021051310016203700155610ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014-2015, 2017, Jon Schlinkert Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. object.defaults-1.1.0/README.md000066400000000000000000000050341310016203700160370ustar00rootroot00000000000000# object.defaults [![NPM version](https://img.shields.io/npm/v/object.defaults.svg?style=flat)](https://www.npmjs.com/package/object.defaults) [![NPM monthly downloads](https://img.shields.io/npm/dm/object.defaults.svg?style=flat)](https://npmjs.org/package/object.defaults) [![NPM total downloads](https://img.shields.io/npm/dt/object.defaults.svg?style=flat)](https://npmjs.org/package/object.defaults) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/object.defaults.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/object.defaults) > Like `extend` but only copies missing properties/values to the target object. ## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm install --save object.defaults ``` Install with [bower](https://bower.io/) ```sh $ bower install object.defaults --save ``` ## Usage ```js var defaults = require('object.defaults'); var obj = {a: 'c'}; defaults(obj, {a: 'bbb', d: 'c'}); console.log(obj); //=> {a: 'c', d: 'c'} ``` Or immutable defaulting: ```js var defaults = require('object.defaults/immutable'); var obj = {a: 'c'}; var defaulted = defaults(obj, {a: 'bbb', d: 'c'}); console.log(obj !== defaulted); //=> true ``` ## About ### Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). ### Contributors | **Commits** | **Contributor** | | --- | --- | | 16 | [jonschlinkert](https://github.com/jonschlinkert) | | 1 | [phated](https://github.com/phated) | | 1 | [sobolevn](https://github.com/sobolevn) | ### Building docs _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ To generate the readme, run the following command: ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ``` ### Running tests Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: ```sh $ npm install && npm test ``` ### Author **Jon Schlinkert** * [github/jonschlinkert](https://github.com/jonschlinkert) * [twitter/jonschlinkert](https://twitter.com/jonschlinkert) ### License Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). Released under the [MIT License](LICENSE). *** _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 26, 2017._object.defaults-1.1.0/bower.json000066400000000000000000000023631310016203700165730ustar00rootroot00000000000000{ "name": "object.defaults", "description": "Like `extend` but only copies missing properties/values to the target object.", "version": "1.0.0", "homepage": "https://github.com/jonschlinkert/object.defaults", "authors": [ "Jon Schlinkert" ], "contributors": [ "Jon Schlinkert (http://twitter.com/jonschlinkert)", "Sobolev Nikita (https://github.com/sobolevn)" ], "repository": "jonschlinkert/object.defaults", "bugs": { "url": "https://github.com/jonschlinkert/object.defaults/issues" }, "license": "MIT", "files": [ "index.js", "LICENSE", "README.md" ], "main": [ "index.js" ], "dependencies": { "array-each": "^1.0.1", "array-slice": "^1.0.0", "for-own": "^1.0.0", "isobject": "^3.0.0" }, "devDependencies": { "gulp-format-md": "^0.1.11", "mocha": "^3.2.0" }, "keywords": [ "copy", "default", "defaults", "extend", "javascript", "js", "merge", "object", "properties", "property", "util", "utils", "value", "values" ], "ignore": [ "actual", "bower_components", "fixtures", "node_modules", "temp", "test", "test.js", "tmp" ] }object.defaults-1.1.0/immutable.js000066400000000000000000000006321310016203700170740ustar00rootroot00000000000000'use strict'; var slice = require('array-slice'); var defaults = require('./mutable'); /** * Extends an empty object with properties of one or * more additional `objects` * * @name .defaults.immutable * @param {Object} `objects` * @return {Object} * @api public */ module.exports = function immutableDefaults() { var args = slice(arguments); return defaults.apply(null, [{}].concat(args)); }; object.defaults-1.1.0/index.js000066400000000000000000000004201310016203700162170ustar00rootroot00000000000000/*! * object.defaults * * Copyright (c) 2014-2015, 2017, Jon Schlinkert. * Released under the MIT License. */ 'use strict'; module.exports = require('./mutable'); module.exports.immutable = require('./immutable'); object.defaults-1.1.0/mutable.js000066400000000000000000000013531310016203700165470ustar00rootroot00000000000000'use strict'; var each = require('array-each'); var slice = require('array-slice'); var forOwn = require('for-own'); var isObject = require('isobject'); /** * Extends the `target` object with properties of one or * more additional `objects` * * @name .defaults * @param {Object} `target` The target object. Pass an empty object to shallow clone. * @param {Object} `objects` * @return {Object} * @api public */ module.exports = function defaults(target, objects) { if (target == null) { return {}; } each(slice(arguments, 1), function(obj) { if (isObject(obj)) { forOwn(obj, function(val, key) { if (target[key] == null) { target[key] = val; } }); } }); return target; }; object.defaults-1.1.0/package.json000066400000000000000000000026101310016203700170430ustar00rootroot00000000000000{ "name": "object.defaults", "description": "Like `extend` but only copies missing properties/values to the target object.", "version": "1.1.0", "homepage": "https://github.com/jonschlinkert/object.defaults", "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "contributors": [ "Jon Schlinkert (http://twitter.com/jonschlinkert)", "Sobolev Nikita (https://github.com/sobolevn)" ], "repository": "jonschlinkert/object.defaults", "bugs": { "url": "https://github.com/jonschlinkert/object.defaults/issues" }, "license": "MIT", "files": [ "index.js", "immutable.js", "mutable.js" ], "main": "index.js", "engines": { "node": ">=0.10.0" }, "scripts": { "test": "mocha" }, "dependencies": { "array-each": "^1.0.1", "array-slice": "^1.0.0", "for-own": "^1.0.0", "isobject": "^3.0.0" }, "devDependencies": { "gulp-format-md": "^0.1.11", "mocha": "^3.2.0" }, "keywords": [ "copy", "default", "defaults", "extend", "javascript", "js", "merge", "object", "properties", "property", "util", "utils", "value", "values" ], "verb": { "toc": false, "layout": "default", "tasks": [ "readme" ], "plugins": [ "gulp-format-md" ], "lint": { "reflinks": true } } } object.defaults-1.1.0/test.js000066400000000000000000000047621310016203700161040ustar00rootroot00000000000000/*! * object.defaults * * Copyright (c) 2014 Jon Schlinkert, contributors. * Licensed under the MIT License */ 'use strict'; require('mocha'); var assert = require('assert'); var defaults = require('./'); describe('defaults', function () { var ctx = {}; beforeEach(function () { ctx.foo = {aaa: 'bbb', ccc: 'ddd'}; ctx.bar = {ccc: 'eee', fff: 'ggg'}; }); it('should mutate the first argument.', function() { assert(defaults(ctx.foo, ctx.bar) === ctx.foo); }); it('should return an empty object when undefined.', function() { assert.deepEqual(defaults(), {}); }); it('should extend the first object with missing properties from the second.', function() { assert.deepEqual(defaults(ctx.foo, ctx.bar), {aaa:'bbb',ccc:'ddd',fff:'ggg'}); }); it('should ignore non-objects.', function() { assert.deepEqual(defaults(ctx.foo, ctx.bar, 'baz'), {aaa:'bbb',ccc:'ddd',fff:'ggg'}); }); it('should use the default object as context.', function() { ctx.bar = {aaa: 'ddd'}; assert.deepEqual(defaults(ctx.foo, ctx.bar), {aaa:'bbb',ccc:'ddd'}, 'should not overwrite `aaa`'); }); it('should copy only missing properties defaults', function () { assert.deepEqual(defaults({a: 'c'}, {a: 'bbb', d: 'c'}), {a: 'c', d: 'c'}); }); it('should copy properties from multiple objects', function () { assert.deepEqual(defaults({a: 'b'}, {c: 'd'}, {e: 'f'}), {a: 'b', c: 'd', e: 'f'}); }); it('should fill in values that are null', function () { assert.deepEqual(defaults({a: null}, {a: 'c', d: 'c'}), {a: 'c', d: 'c'}); }); it('should not merge nested values.', function () { assert.deepEqual(defaults({a: {b: 'c'}}, {a: {d: 'e'}}), {a: {b: 'c'}}); }); it('should shallow clone when an empty object is passed as the first arg.', function () { assert.deepEqual(defaults({}, {a: {b: 'c'}}, {a: {d: 'e'}}), {a: {b: 'c'}}); }); it('should return an empty object when the first arg is null.', function () { assert.deepEqual(defaults(null), {}); }); }); describe('defaults.immutable', function () { var ctx = {}; beforeEach(function () { ctx.foo = {aaa: 'bbb', ccc: 'ddd'}; ctx.bar = {ccc: 'eee', fff: 'ggg'}; }); it('should not mutate the first argument.', function() { var result = defaults.immutable(ctx.foo, ctx.bar); assert(result !== ctx.foo); assert.deepEqual(ctx.foo, {aaa: 'bbb', ccc: 'ddd'}); assert.deepEqual(result, {aaa:'bbb',ccc:'ddd',fff:'ggg'}); }); });