Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
mixinable
is a small utility library allowing you to use mixins in your code. Apart from enabling you to add and override new methods to your prototypes, it helps you apply different strategies to those additional methods.
mixinable
keeps your protoype chain intact (instanceof
works as expected), allows you to provide custom constructor
functions and supports asynchronous methods returning Promises
.
Using NPM:
npm install -S mixinable
Using Yarn:
yarn add mixinable
mixin([...definition])
The main export of mixinable
is a variadic function accepting any number of mixin definitions. It returns a constructor/factory function that creates instances containing the mixin methods you defined.
T.B.D. - to be documented
mixin.replace([...implementation])
T.B.D. - to be documented
mixin.parallel([...implementation])
T.B.D. - to be documented
mixin.pipe([...implementation])
T.B.D. - to be documented
mixin.sequence([...implementation])
import mixin from 'mixinable';
// const Foo = mixin({
const createFoo = mixin({
bar() {
// ...
}
});
// const foo = new Foo();
const foo = createFoo();
// console.log(foo instanceof Foo);
console.log(foo instanceof createFoo);
import mixin from 'mixinable';
// multiple mixin arguments are being merged
const createFoo = mixin(
{
bar() {
// ...
}
},
{
// you can pass multiple implementations at once
baz: [
function () { /* ... */ },
function () { /* ... */ }
]
}
);
// constructors/factories created with mixin can be extended
const createQux = createFoo.mixin({
bar() {
// ...
}
});
parallel
Exampleimport mixin, { parallel } from 'mixinable';
// const Foo = mixin({
const createFoo = mixin({
bar: parallel(
function () {
return Promise.resolve(1);
},
function () {
return Promise.resolve(2);
}
)
});
const foo = createFoo();
foo.bar().then(res => console.log(res));
// [1, 2]
pipe
Exampleimport mixin, { pipe } from 'mixinable';
// const Foo = mixin({
const createFoo = mixin({
bar: pipe(
function (val, inc) {
return Promise.resolve(val + inc);
},
function (val, inc) {
return (val + inc);
}
)
});
const foo = createFoo();
foo.bar(0, 1).then(res => console.log(res));
// 2
sequence
Exampleimport mixin, { sequence } from 'mixinable';
// const Foo = mixin({
const createFoo = mixin({
bar: sequence(
function (options) {
this.baz = options.baz;
},
function (options) {
this.qux = this.bar * 42;
}
)
});
const foo = createFoo();
foo.bar({ baz: 23 });
console.log(foo.qux);
// '966'
If you want to contribute to this project, create a fork of its repository using the GitHub UI. Check out your new fork to your computer:
mkdir mixinable && cd $_
git clone git@github.com:user/mixinable.git
Afterwards, you can yarn install
the required dev dependencies and start hacking away. When you are finished, please do go ahead and create a pull request.
mixinable
is entirely written in ECMAScript 5 and adheres to semistandard code style. Please make sure your contribution does, too.
FAQs
Functional JavaScript Mixin Utility
The npm package mixinable receives a total of 171 weekly downloads. As such, mixinable popularity was classified as not popular.
We found that mixinable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.