Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@knowark/injectarkjs

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@knowark/injectarkjs - npm Package Compare versions

Comparing version 0.10.2 to 0.10.3

14

lib/builder.js

@@ -9,8 +9,14 @@ export class Builder {

const name = config.factory || this.base
const names = (name || Object.keys(
const [pivot, ...overrides] = (name || Object.keys(
this.factories).shift()).split(',').map(name => name.trim())
const Constructor = this.factories[names.slice().pop()]
return names.reduce((store, item) => Object.assign(
store, item), new Constructor(config))
const Constructor = this.factories[pivot]
const factory = new Constructor(config)
for (const override of overrides) {
const prototype = this.factories[override].prototype
for (const property of Object.getOwnPropertyNames(prototype)) {
factory[property] = prototype[property]
}
}
return factory
}
}

@@ -8,5 +8,12 @@ import { describe, it, expect } from '@jest/globals'

class AlphaFactory extends Factory {}
class BetaFactory extends Factory {}
class GammaFactory extends Factory {}
class AlphaFactory extends Factory {
alphaMethod () { return 'ALPHA:alpha' }
}
class BetaFactory extends AlphaFactory {
betaMethod () { return 'BETA:beta' }
}
class GammaFactory extends BetaFactory {
alphaMethod () { return 'GAMMA:alpha' }
gammaMethod () { return 'GAMMA:gamma' }
}

@@ -50,17 +57,36 @@ const factories = {

let factory = builder.build({
factory: 'beta,alpha'
})
let factory = builder.build({ factory: 'beta,alpha' })
expect(factory).toBeInstanceOf(BetaFactory)
expect(factory.alphaMethod()).toEqual('ALPHA:alpha')
expect(factory.betaMethod()).toEqual('BETA:beta')
expect(() => factory.gammaMethod()).toThrow()
factory = builder.build({ factory: 'alpha,beta' })
expect(factory).toBeInstanceOf(AlphaFactory)
expect(factory.alphaMethod()).toEqual('ALPHA:alpha')
expect(factory.betaMethod()).toEqual('BETA:beta')
expect(() => factory.gammaMethod()).toThrow()
factory = builder.build({
factory: 'alpha,beta'
})
factory = builder.build({ factory: 'alpha, beta, gamma' })
expect(factory).toBeInstanceOf(AlphaFactory)
expect(factory.alphaMethod()).toEqual('GAMMA:alpha')
expect(factory.betaMethod()).toEqual('BETA:beta')
expect(factory.gammaMethod()).toEqual('GAMMA:gamma')
factory = builder.build({ factory: 'gamma, alpha, beta' })
expect(factory).toBeInstanceOf(AlphaFactory)
expect(factory).toBeInstanceOf(BetaFactory)
expect(factory).toBeInstanceOf(GammaFactory)
expect(factory.alphaMethod()).toEqual('ALPHA:alpha')
expect(factory.betaMethod()).toEqual('BETA:beta')
expect(factory.gammaMethod()).toEqual('GAMMA:gamma')
factory = builder.build({
factory: 'alpha, beta, gamma'
})
factory = builder.build({ factory: 'gamma, beta, alpha' })
expect(factory).toBeInstanceOf(AlphaFactory)
expect(factory).toBeInstanceOf(BetaFactory)
expect(factory).toBeInstanceOf(GammaFactory)
expect(factory.alphaMethod()).toEqual('ALPHA:alpha')
expect(factory.betaMethod()).toEqual('BETA:beta')
expect(factory.gammaMethod()).toEqual('GAMMA:gamma')
})
})
{
"name": "@knowark/injectarkjs",
"version": "0.10.2",
"version": "0.10.3",
"description": "Dependency Injector for Javascript",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc