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

kp-merge

v1.0.9

Published

对象的拷贝,合并等, 使用说明请参考 readme

Downloads

5

Readme

一、内置方法: 可以使用 import { functionName } 调用

1. 设定属性 setProp(Object, String|Array, Any, Boolean?):void

        使用方法: const a = {}; setProp(a, 'c1.c2.name', 10); -> a = {c1: c2: {name: 10}};
                  const a = {c1: c2: {name: 'c2'}}; setProp(a, 'c1.c2.name', 11, false); -> a.c1.c2.name = 'c2'; 
                  // 最后一个参数主要用于 当不确定是否存在某个参数时候,如果存在,是否覆盖,默认覆盖,false 为不覆盖


2. 获取属性 getProp(Object, String|Array):any

        使用方法:getProp(a, 'c1.c2.name');

3. 检测属性是否存在 checkProp(Object, String|Array): boolean
        使用方法: checkProp(a, 'c1.c2.name'); 

4. 深度拷贝 cloneDeep(Object: T): T 

        使用方法 b = {name: 'b', c1: {name: 'b_c1', function(){}}}; a = cloneDeep(b); -> a = {name: 'b', c1: {name: 'b_c1', function(){}}};


5. 深度合并 mergeDeep(Object: T, Object: K, Boolean?): K 

        使用方法 a = {name_1: 'a', c: { age: 10} }; b = {name: 'b',c: { age: 11} }; mergeDeep(a, b); -> a = {name_1: 'a', name: 'b', c: { age: 10} }; // 同名引用类型合并,基础类型覆盖
                q = {name_1: 'a', c: { age: 10} }; w = {name: 'b',c: { ok: 1} }; mergeDeep(q, w, true); // 最后一个参数传 true 同名引用类型 后者覆盖前者

二、内置类:

    使用方法:
    import Merge from 'kp-merge';
    const a = {name_1: 'a', children: ['a_1', 'a_2']};
    const b = {name_2: 'b', children: ['b_1', 'b_2']};
    const c = {name: 'c', fn: function(){console.log(this)}}
    const merge  = new Merge(a, b, c); // arguments : ...Object[]?
    
    1. merge.value 
            // 获取合并值

                {name_1: "a", children: ['b_1', 'b_2'], name_2: "b", name: "c", fn: ƒ}            
    
    2.  merge.set(String|Array, Any);
            // 设定属性(可设定undefined的属性,支持多层)
            // merge.set('test.testChild.testChildProp', {propName: 'name'});
    
    3.  merge.merge(Object)
            // 新增合并对象
            // merge.merge({name_3: 'aa', child: {name: 'child'}})   

    4. merge.overWrite(...Object[]?)
            // 重写 merge.value
            // merge.overWrite()
            // merge.overWrite({name: 1})
            // merge.overWrite({name: 1}, {age: 2})
    
    5. merge.cover(Object)
            // 覆盖同名引用类型