@openreachtech/mentsu-gene-chain-splicer
v1.0.1
Published
GeneChainSplicer module for Mentsu
Readme
mentsu-gene-chain-splicer
A JavaScript utility for dynamically extending object instances by splicing methods into their prototype chain.
Installation
Prerequisites
- Node.js >= 20.0.0
- npm >= 10.0.0
Setting up .npmrc
This package is published to GitHub Packages. Create a .npmrc file in your project root:
@openreachtech:registry=https://npm.pkg.github.comInstall
npm install @openreachtech/mentsu-gene-chain-splicerUsage
Import the module:
import {
GeneChainSplicer,
} from '@openreachtech/mentsu-gene-chain-splicer'(1) Basic Example
Override a single method:
class AlphaCore {
firstValue () {
return 1000
}
}
const alphaCore = new AlphaCore()
const splicer = GeneChainSplicer.create({
core: alphaCore,
})
splicer.spliceGene({
mixin: {
firstValue () {
return 1999
},
},
})
console.log(alphaCore.firstValue()) // 1999(2) Multiple Members
Override multiple members at once:
class BetaCore {
firstValue () {
return 2000
}
secondValue () {
return 3000
}
}
const betaCore = new BetaCore()
const splicer = GeneChainSplicer.create({
core: betaCore,
})
splicer.spliceGene({
mixin: {
firstValue () {
return 2999
},
secondValue () {
return 3999
},
},
})
console.log(betaCore.firstValue()) // 2999
console.log(betaCore.secondValue()) // 3999(3) Method Chaining
Chain multiple spliceGene() calls:
class GammaCore {
firstValue () {
return 4000
}
secondValue () {
return 5000
}
}
const gammaCore = new GammaCore()
const splicer = GeneChainSplicer.create({
core: gammaCore,
})
splicer
.spliceGene({
mixin: {
firstValue () {
return 4999
},
},
})
.spliceGene({
mixin: {
secondValue () {
return 5999
},
},
})
console.log(gammaCore.firstValue()) // 4999
console.log(gammaCore.secondValue()) // 5999(4) Splice Order
Later splices take precedence over earlier ones:
class DeltaCore {
firstValue () {
return 6000
}
}
const deltaCore = new DeltaCore()
const splicer = GeneChainSplicer.create({
core: deltaCore,
})
splicer
.spliceGene({
mixin: {
firstValue () {
return 6999
},
},
})
.spliceGene({
mixin: {
firstValue () {
return 6888
},
},
})
console.log(deltaCore.firstValue()) // 6888Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
git clone https://github.com/openreachtech/mentsu-gene-chain-splicer.git
cd mentsu-gene-chain-splicer
npm install
npm run lint
npm testLicense
This project is released under the MIT License.
For more details, please see in the LICENSE file.
Developer
Copyright
© 2026 Open Reach Tech Inc.
