npm.io
1.0.23 • Published 5 years ago

obj-spread

Licence
MIT
Version
1.0.23
Deps
0
Size
4 kB
Vulns
0
Weekly
0

A simple, but powerful way to extend classes with other classes. You can even extend built-in classes, like Array or String

Installation

npm i obj-spread -S

Usage

For example, you want to move all static functions from class Foo to internal class String. All you need to do is to create an instance of ObjSpread:

    new ObjSpread(Foo, String, s=>String(s));

Here, the last argument will convert the value to an actual String class. For example, if you want to spread to Array, you would do the following:

    new ObjSpread(Foo, Array, a=>[].concat(a));

In case if you don't need to convert anything, just do a=>a.