pax_global_header00006660000000000000000000000064134552162340014517gustar00rootroot0000000000000052 comment=92ffccc595a72a12bdf822e761e81f59800d7a42 shallow-clone-3.0.1/000077500000000000000000000000001345521623400142675ustar00rootroot00000000000000shallow-clone-3.0.1/.editorconfig000066400000000000000000000004411345521623400167430ustar00rootroot00000000000000# http://editorconfig.org/ root = true [*] charset = utf-8 end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true trim_trailing_whitespace = true [{**/{actual,fixtures,expected,templates}/**,*.md}] trim_trailing_whitespace = false insert_final_newline = false shallow-clone-3.0.1/.eslintrc.json000066400000000000000000000073251345521623400170720ustar00rootroot00000000000000{ "extends": [ "eslint:recommended" ], "env": { "browser": false, "es6": true, "node": true, "mocha": true }, "parserOptions":{ "ecmaVersion": 9, "sourceType": "module", "ecmaFeatures": { "modules": true, "experimentalObjectRestSpread": 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"] } } shallow-clone-3.0.1/.gitattributes000066400000000000000000000002001345521623400171520ustar00rootroot00000000000000# Enforce Unix newlines * text eol=lf # binaries *.ai binary *.psd binary *.jpg binary *.gif binary *.png binary *.jpeg binary shallow-clone-3.0.1/.gitignore000066400000000000000000000004561345521623400162640ustar00rootroot00000000000000# always ignore files *.DS_Store .idea .vscode *.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 package-lock.jsonshallow-clone-3.0.1/.travis.yml000066400000000000000000000001641345521623400164010ustar00rootroot00000000000000sudo: false os: - linux - osx - windows language: node_js node_js: - node - '11' - '10' - '9' - '8' shallow-clone-3.0.1/.verb.md000066400000000000000000000023251345521623400156270ustar00rootroot00000000000000## Usage ```js const clone = require('{%= name %}'); ``` **Supports** - array buffers - arrays - buffers - dates - errors - float32 arrays - float64 arrays - int16 arrays - int32 arrays - int8 arrays - maps - objects - primitives - regular expressions - sets - symbols - uint16 arrays - uint32 arrays - uint8 arrays - uint8clamped arrays ## Arrays By default, only the array itself is cloned (shallow), use [clone-deep][] if you also need the elements in the array to be cloned. ```js const arr = [{ a: 0 }, { b: 1 }]; const foo = clone(arr); // foo => [{ 'a': 0 }, { 'b': 1 }] // array is cloned assert(actual === expected); // false // array elements are not assert.deepEqual(actual[0], expected[0]); // true ``` ## Objects Only the object is shallow cloned, use [clone-deep][] if you also need the values in the object to be cloned. ```js console.log(clone({ a: 1, b: 2, c: 3 })); //=> {a: 1, b: 2, c: 3 } ``` ## RegExp Clones regular expressions and flags, and preserves the `.lastIndex`. ```js const regex = clone(/foo/g); //=> /foo/g // you can manually reset lastIndex if necessary regex.lastIndex = 0; ``` ## Primitives Simply returns primitives unchanged. ```js clone(0); //=> 0 clone('foo'); //=> 'foo' ```shallow-clone-3.0.1/LICENSE000066400000000000000000000021031345521623400152700ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015-present, 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. shallow-clone-3.0.1/README.md000066400000000000000000000121401345521623400155440ustar00rootroot00000000000000# shallow-clone [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/shallow-clone.svg?style=flat)](https://www.npmjs.com/package/shallow-clone) [![NPM monthly downloads](https://img.shields.io/npm/dm/shallow-clone.svg?style=flat)](https://npmjs.org/package/shallow-clone) [![NPM total downloads](https://img.shields.io/npm/dt/shallow-clone.svg?style=flat)](https://npmjs.org/package/shallow-clone) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/shallow-clone.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/shallow-clone) > Creates a shallow clone of any JavaScript value. Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. ## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm install --save shallow-clone ``` ## Usage ```js const clone = require('shallow-clone'); ``` **Supports** * array buffers * arrays * buffers * dates * errors * float32 arrays * float64 arrays * int16 arrays * int32 arrays * int8 arrays * maps * objects * primitives * regular expressions * sets * symbols * uint16 arrays * uint32 arrays * uint8 arrays * uint8clamped arrays ## Arrays By default, only the array itself is cloned (shallow), use [clone-deep](https://github.com/jonschlinkert/clone-deep) if you also need the elements in the array to be cloned. ```js const arr = [{ a: 0 }, { b: 1 }]; const foo = clone(arr); // foo => [{ 'a': 0 }, { 'b': 1 }] // array is cloned assert(actual === expected); // false // array elements are not assert.deepEqual(actual[0], expected[0]); // true ``` ## Objects Only the object is shallow cloned, use [clone-deep](https://github.com/jonschlinkert/clone-deep) if you also need the values in the object to be cloned. ```js console.log(clone({ a: 1, b: 2, c: 3 })); //=> {a: 1, b: 2, c: 3 } ``` ## RegExp Clones regular expressions and flags, and preserves the `.lastIndex`. ```js const regex = clone(/foo/g); //=> /foo/g // you can manually reset lastIndex if necessary regex.lastIndex = 0; ``` ## Primitives Simply returns primitives unchanged. ```js clone(0); //=> 0 clone('foo'); //=> 'foo' ``` ## About
Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
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 ```
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 ```
### Related projects You might also be interested in these projects: * [assign-deep](https://www.npmjs.com/package/assign-deep): Deeply assign the values of all enumerable-own-properties and symbols from one or more source objects… [more](https://github.com/jonschlinkert/assign-deep) | [homepage](https://github.com/jonschlinkert/assign-deep "Deeply assign the values of all enumerable-own-properties and symbols from one or more source objects to a target object. Returns the target object.") * [clone-deep](https://www.npmjs.com/package/clone-deep): Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. | [homepage](https://github.com/jonschlinkert/clone-deep "Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.") * [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor. | [homepage](https://github.com/jonschlinkert/is-plain-object "Returns true if an object was created by the `Object` constructor.") * [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.") ### Contributors | **Commits** | **Contributor** | | --- | --- | | 20 | [jonschlinkert](https://github.com/jonschlinkert) | | 2 | [doowb](https://github.com/doowb) | | 1 | [jakub-g](https://github.com/jakub-g) | ### Author **Jon Schlinkert** * [GitHub Profile](https://github.com/jonschlinkert) * [Twitter Profile](https://twitter.com/jonschlinkert) * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) ### License Copyright © 2019, [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.8.0, on April 15, 2019._shallow-clone-3.0.1/index.js000066400000000000000000000035371345521623400157440ustar00rootroot00000000000000/*! * shallow-clone * * Copyright (c) 2015-present, Jon Schlinkert. * Released under the MIT License. */ 'use strict'; const valueOf = Symbol.prototype.valueOf; const typeOf = require('kind-of'); function clone(val, deep) { switch (typeOf(val)) { case 'array': return val.slice(); case 'object': return Object.assign({}, val); case 'date': return new val.constructor(Number(val)); case 'map': return new Map(val); case 'set': return new Set(val); case 'buffer': return cloneBuffer(val); case 'symbol': return cloneSymbol(val); case 'arraybuffer': return cloneArrayBuffer(val); case 'float32array': case 'float64array': case 'int16array': case 'int32array': case 'int8array': case 'uint16array': case 'uint32array': case 'uint8clampedarray': case 'uint8array': return cloneTypedArray(val); case 'regexp': return cloneRegExp(val); case 'error': return Object.create(val); default: { return val; } } } function cloneRegExp(val) { const flags = val.flags !== void 0 ? val.flags : (/\w+$/.exec(val) || void 0); const re = new val.constructor(val.source, flags); re.lastIndex = val.lastIndex; return re; } function cloneArrayBuffer(val) { const res = new val.constructor(val.byteLength); new Uint8Array(res).set(new Uint8Array(val)); return res; } function cloneTypedArray(val, deep) { return new val.constructor(val.buffer, val.byteOffset, val.length); } function cloneBuffer(val) { const len = val.length; const buf = Buffer.allocUnsafe ? Buffer.allocUnsafe(len) : Buffer.from(len); val.copy(buf); return buf; } function cloneSymbol(val) { return valueOf ? Object(valueOf.call(val)) : {}; } /** * Expose `clone` */ module.exports = clone; shallow-clone-3.0.1/package.json000066400000000000000000000023441345521623400165600ustar00rootroot00000000000000{ "name": "shallow-clone", "description": "Creates a shallow clone of any JavaScript value.", "version": "3.0.1", "homepage": "https://github.com/jonschlinkert/shallow-clone", "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "contributors": [ "Brian Woodward (https://twitter.com/doowb)", "Jon Schlinkert (http://twitter.com/jonschlinkert)" ], "repository": "jonschlinkert/shallow-clone", "bugs": { "url": "https://github.com/jonschlinkert/shallow-clone/issues" }, "license": "MIT", "files": [ "index.js" ], "main": "index.js", "engines": { "node": ">=8" }, "scripts": { "test": "mocha" }, "dependencies": { "kind-of": "^6.0.2" }, "devDependencies": { "gulp-format-md": "^2.0.0", "mocha": "^6.1.3" }, "keywords": [ "array", "clone", "copy", "extend", "mixin", "object", "primitive", "shallow" ], "verb": { "toc": false, "layout": "default", "tasks": [ "readme" ], "plugins": [ "gulp-format-md" ], "lint": { "reflinks": true }, "related": { "list": [ "assign-deep", "clone-deep", "is-plain-object", "kind-of" ] } } } shallow-clone-3.0.1/test.js000066400000000000000000000044131345521623400156060ustar00rootroot00000000000000'use strict'; require('mocha'); const assert = require('assert').strict; const clone = require('./'); describe('clone()', () => { describe('objects', () => { it('should shallow clone an array of primitives', () => { assert.deepEqual(clone(['alpha', 'beta', 'gamma']), ['alpha', 'beta', 'gamma']); }); it('should shallow clone an array with varied elements', () => { const val = [0, 'a', {}, [{}], [function() {}], function() {}]; assert.deepEqual(clone(val), val); }); it('should clone Map', () => { const a = new Map([[1, 5]]); const b = clone(a); a.set(2, 4); assert.notDeepEqual(a, b); }); it('should clone Set', () => { const a = new Set([2, 1, 3]); const b = clone(a); a.add(8); assert.notDeepEqual(a, b); }); it('should shallow clone arrays', () => { assert(clone([1, 2, 3]) !== [1, 2, 3]); assert.deepEqual(clone([1, 2, 3]), [1, 2, 3]); }); it('should shallow clone a regex with flags', () => { assert(clone(/foo/g) !== /foo/g); assert.deepEqual(clone(/foo/g), /foo/g); }); it('should shallow clone a regex without any flags', () => { assert(clone(/foo/) !== /foo/); assert.deepEqual(clone(/foo/), /foo/); }); it('should shallow clone a date', () => { const date = new Date(); assert(clone(date) !== date); assert.deepEqual(clone(date), date); }); it('should shallow clone objects', () => { assert.deepEqual(clone({ a: 1, b: 2, c: 3 }), { a: 1, b: 2, c: 3 }); }); it('should shallow clone an array of objects.', () => { const expected = [{ a: 0 }, { b: 1 }]; const actual = clone(expected); assert(actual !== expected); assert.deepEqual(actual, expected); assert.deepEqual(actual[0], expected[0]); }); }); describe('primitives', () => { it('should return primitives', () => { assert.equal(clone(0), 0); assert.equal(clone(1), 1); assert.equal(clone('foo'), 'foo'); }); it('should clone symbols', () => { const val = { prop: Symbol() }; const cloned = clone(val); assert.equal(typeof cloned.prop, 'symbol'); assert.notEqual(cloned, val); assert.equal(cloned.prop, val.prop); }); }); });