All Projects → jonschlinkert → Shallow Clone

jonschlinkert / Shallow Clone

Licence: mit
Make a shallow clone of an object, array or primitive.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Shallow Clone

Kind Of
Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
Stars: ✭ 268 (+1065.22%)
Mutual labels:  array, object, regex
Minta
✳️  Electron app for generating regular expressions
Stars: ✭ 353 (+1434.78%)
Mutual labels:  regex, regular-expression
Morphism
⚡ Type-safe data transformer for JavaScript, TypeScript & Node.js.
Stars: ✭ 336 (+1360.87%)
Mutual labels:  array, object
Regexplain
🔍 An RStudio addin slash regex utility belt
Stars: ✭ 413 (+1695.65%)
Mutual labels:  regex, regular-expression
Anymatch
‼️ Matches strings against configurable strings, globs, regular expressions, and/or functions
Stars: ✭ 289 (+1156.52%)
Mutual labels:  regex, regular-expression
Regex
Regular expressions for swift
Stars: ✭ 306 (+1230.43%)
Mutual labels:  regex, regular-expression
Picomatch
Blazing fast and accurate glob matcher written JavaScript, with no dependencies and full support for standard and extended Bash glob features, including braces, extglobs, POSIX brackets, and regular expressions.
Stars: ✭ 393 (+1608.7%)
Mutual labels:  regex, regular-expression
pcre-net
PCRE.NET - Perl Compatible Regular Expressions for .NET
Stars: ✭ 114 (+395.65%)
Mutual labels:  regex, regular-expression
Regulex
🚧 Regular Expression Excited!
Stars: ✭ 4,877 (+21104.35%)
Mutual labels:  regex, regular-expression
Deep Object Diff
Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️
Stars: ✭ 515 (+2139.13%)
Mutual labels:  array, object
Commonregex
🍫 A collection of common regular expressions for Go
Stars: ✭ 733 (+3086.96%)
Mutual labels:  regex, regular-expression
Rex
Your RegEx companion.
Stars: ✭ 283 (+1130.43%)
Mutual labels:  regex, regular-expression
Re Flex
The regex-centric, fast lexical analyzer generator for C++ with full Unicode support. Faster than Flex. Accepts Flex specifications. Generates reusable source code that is easy to understand. Introduces indent/dedent anchors, lazy quantifiers, functions for lex/syntax error reporting, and more. Seamlessly integrates with Bison and other parsers.
Stars: ✭ 274 (+1091.3%)
Mutual labels:  regex, regular-expression
Generex
A Java library for generating String from a regular expression.
Stars: ✭ 316 (+1273.91%)
Mutual labels:  regex, regular-expression
Moses
Utility library for functional programming in Lua
Stars: ✭ 541 (+2252.17%)
Mutual labels:  array, object
Regexp2
A full-featured regex engine in pure Go based on the .NET engine
Stars: ✭ 389 (+1591.3%)
Mutual labels:  regex, regular-expression
genex
Genex package for Go
Stars: ✭ 64 (+178.26%)
Mutual labels:  regex, regular-expression
extglob
Extended globs. Add (almost) the expressive power of regular expressions to glob patterns.
Stars: ✭ 25 (+8.7%)
Mutual labels:  regex, regular-expression
Chinamobilephonenumberregex
Regular expressions that match the mobile phone number in mainland China. / 一组匹配中国大陆手机号码的正则表达式。
Stars: ✭ 4,440 (+19204.35%)
Mutual labels:  regex, regular-expression
Onigmo
Onigmo is a regular expressions library forked from Oniguruma.
Stars: ✭ 536 (+2230.43%)
Mutual labels:  regex, regular-expression

shallow-clone Donate NPM version NPM monthly downloads NPM total downloads Linux Build Status

Creates a shallow clone of any JavaScript value.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.

Install

Install with npm:

$ npm install --save shallow-clone

Usage

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 if you also need the elements in the array to be cloned.

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.

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.

const regex = clone(/foo/g); //=> /foo/g
// you can manually reset lastIndex if necessary
regex.lastIndex = 0;

Primitives

Simply returns primitives unchanged.

clone(0); //=> 0
clone('foo'); //=> 'foo'

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

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:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

  • assign-deep: Deeply assign the values of all enumerable-own-properties and symbols from one or more source objects… more | homepage
  • clone-deep: Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. | homepage
  • is-plain-object: Returns true if an object was created by the Object constructor. | homepage
  • kind-of: Get the native type of a value. | homepage

Contributors

Commits Contributor
20 jonschlinkert
2 doowb
1 jakub-g

Author

Jon Schlinkert

License

Copyright © 2019, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.8.0, on April 15, 2019.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].