npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

copy-own

v1.2.0

Published

Copies an object’s own properties to another object.

Downloads

8,040

Readme

copy-own

Copies an object’s own properties to another object.

“Own” properties are those that are not inherited from the prototype chain.

Installation

Requires Node.js 6.0.0 or above.

npm i copy-own

API

The module exports a single function.

Parameters

  1. from (object): The source object that possesses the properties to be copied.
  2. Optional: to (object): The destination object that should receive the copied properties. Defaults to a new object.
  3. Optional: Object argument:
    • enumOnly (boolean): Whether or not to limit the copy operation to only those properties that were defined with the enumerable flag. Defaults to false.
    • override (boolean): If omitted or set to true, all properties will be copied (unless overwrite specifies otherwise). If set to false, then existing properties in to will be neither overwritten nor overridden; that is, the copy operation will only include properties that do not share a name with properties already existing in to or in its prototype chain.
    • overwrite (boolean): This property is only taken into consideration if override (see above) is omitted or set to true. If this property is also omitted or set to true, all properties will be copied (the default behavior). If set to false, then existing properties in to will not be overwritten, but properties higher up in to’s prototype chain could still be overridden.

Return Value

The function modifies the second argument (to) and returns it. If to is omitted, a new object is created and returned.

Examples

const copyOwn = require('copy-own')

const from = {a: 'from', b: 'from'}
const to = {b: 'to', c: 'to'}
const to = copyOwn(from, to)
to.a // 'from'
to.b // 'from'
to.c // 'to'

Here is the same example repeated with overwrite set to false:

const copyOwn = require('copy-own')

const from = {a: 'from', b: 'from'}
const to = {b: 'to', c: 'to'}
const to = copyOwn(from, to, {overwrite: false})
to.a // 'from'
to.b // 'to'
to.c // 'to'

When no destination object is specified, a new object is created:

const copyOwn = require('copy-own')

const from = {a: 1, b: 2}
const to = copyOwn(from)
to.a // 1
to.b // 2