Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
class-config-base
Advanced tools
The base class of a configuration class for a interfacial class.
npm i class-config-base --save
Load this module.
const ClassConfigBase = require('class-config-base')
Define default config object. This object determines the property default values, the property structure and the property data types of the target class config object.
const defaultConfig = { a: '', b: { c: 0, d: false } }
Define the class config class. getAccessorDescriptors
method is optional and creates descriptors to override property accessors. getInterfaceDescriptors
method creates descriptors to define properties and methods of the target interfacial class.
class MyClassConfig extends ClassConfigBase {
constructor (initConfig) {
super(initConfig, defaultConfig)
}
getAccessorDescriptors () {
return {
'b.c': parent => ({
get () { return parent.a },
set (v) { parent.a = Math.max(0, v) },
}),
}
}
getInterfaceDescriptors () {
const self = this
return {
myA: { /* to make a read-only property */
enumerable: true,
set () {},
get () { return self.a },
},
myC: { /* to make a restricted property */
enumerable: true,
set (v) { if (self.b.d) { self.b.c = v } },
get () { return self.b.c },
},
myD: {
enumerable: true,
set (v) { self.b.d = v },
get () { return self.b.d },
},
}
}
}
Define the interfacial class with the class config.
class MyClass {
constructor (myClassConfig) {
myClassConfig.configure(this)
}
}
Instantiate and use the interfacial class.
const myClassConfig = new MyClassConfig({ a: 'Foo', b: { c: 123, d: true } })
const myObj = new MyClass(myClassConfig)
console.log(myObj.toString()) // [object MyClass]
console.log(Object.prototype.toString.call(myObj)) // [object MyClass]
console.log(myObj.myA) // 'Foo'
console.log(myObj.myC) // 123
console.log(myObj.myD) // true
myObj.myA = 'Bar'
console.log(myObj.myA) // 'Foo'
myObj.myC = 999
console.log(myObj.myC) // 999
myObj.myC = -888
console.log(myObj.myC) // 0
myObj.myD = false
console.log(myObj.myD) // false
myObj.myC = 777
console.log(myObj.myC) // 0
A property value, even if it is read-only, can be updated with the class config object.
myClassConfig.a = 'Buz'
myClassConfig.b.c = 666
console.log(myObj.myA) // 'Buz'
console.log(myObj.myC) // 666
console.log(myObj.myD) // false
Constructs a configuration class instance. initConfig and defaultConfig is plain objects and can be nested objects. defaultConfig is to specify the default values and the types of the properties. So if a property in initConfig is different from a corresponding property in defaultConfig, the property value in initConfig is ignored.
Parameters:
Returns an object which maps between property key chains and functions which get property descriptors.
A key chain concatenates all keys in a key path with dots. A descriptor is the one used by Object.defineProperty
.
This method is to override configure accessors of the config class.
Returns:
The format of an entry in the returned object is as follows:
getAccessorDescriptors () {
return {
/* An example of an entry in the returned object */
'a.b.c' : function (parent, key, info) {
return {
enumerable: true,
configurable: false,
get () { return parent[key] },
set (v) { parent[key] = v },
}
},
...
}
}
The entry is a function of which the arguments are parent, key, info.
In the above example, parent equals to config.a.b
, and key equals to 'c'
. info is same with nodeInfo of each-props.
Returns an object which maps between property name and property descriptors. A descriptor is the one used by Object.defineProperty
.
This method defines the interfaces of the target class.
Returns:
The format of an entry in the returned object is as follows:
getInterfaceDescriptors () {
const self = this
return {
/* An example of an entry in the returned object */
'c' : {
return {
enumerable: true,
configurable: false,
get () { return self.a.b.c },
set (v) { self.a.b.c = v },
}
},
...
}
}
Configures the interfaces of the target class instance in its constructor.
Parameters:
Copyright (C) 2017 Takayuki Sato
This program is free software under MIT License. See the file LICENSE in this distribution for more details.
FAQs
The base class of a configuration class for a interfacial class.
The npm package class-config-base receives a total of 614 weekly downloads. As such, class-config-base popularity was classified as not popular.
We found that class-config-base demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.