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.
custom-factory
Advanced tools
more easily add the factory ability to your class for node and javascript
easily add the factory ability to your class which can singleton, name, register/unregister and aliases your object items.
The factory could be hierarchical or flat. defaults to hierarchical. The flat factory means register only on the Root Factory.
for coffee-script:
factory = require 'custom-factory'
class Codec
# make the Codec factory-able:
factory Codec
# if you wanna a flat factory:
#factory Codec, flatOnly: true
constructor: (aName, aOptions)->return super
# the constructor's aOptions will be passed through
initialize: (aOptions)->
@bufferSize = aOptions.bufSize if aOptions
# your factory methods:
encode: (aValue)->
register = Codec.register
aliases = Codec.aliases
class TextCodec
register TextCodec
aliases TextCodec, 'utf8', 'utf-8'
constructor: Codec
encode: (aValue)->
class JsonCodec
register JsonCodec, TextCodec
constructor: -> return super
encode: (aValue)->
class TestCodec
# register with a specified name:
register TestCodec, 'MyTest'
# or like this:
# register TestCodec, name: 'MyTest'
for javascript:
var factory = require('custom-factory')
// Class Codec
function Codec(){
return Codec.__super__.constructor.apply(this, arguments);
}
// make the Codec factory-able:
factory(Codec)
// if you wanna a flat factory:
// factory(Codec, {flatOnly: true})
// the constructor's aOptions will be passed through
Codec.prototype.initialize = function(aOptions){
if (aOptions)
this.bufferSize = aOptions.bufSize
}
// your factory methods:
Codec.prototype.encode = function(aValue){}
var register = Codec.register
var aliases = Codec.aliases
// Class TextCodec
function TextCodec() {
Codec.apply(this, arguments)
}
register(TextCodec)
aliases(TextCodec, 'utf8', 'utf-8')
TextCodec.prototype.encode = function(aValue){}
// class JsonCodec
function JsonCodec() {
TextCodec.apply(this, arguments)
}
register(JsonCodec)
JsonCodec.prototype.encode = function(aValue){}
// class TestCodec
function TestCodec() {
Codec.apply(this, arguments)
}
// register with a specified name:
register(TestCodec, 'MyTest')
// or like this:
// register(TestCodec, {name: 'MyTest'})
var TextCodec = Codec['Text'] // # get the JsonCodec Class
var JsonCodec = Codec['Json'] // # note: name is case-sensitive!
var JsonCodec = TextCodec['Json'] // # or like this
var json = Codec('Json', bufSize: 12) // # get the singleton instance from the Codec
var json = JsonCodec() // # or like this
var text = Codec('Text') // # or Codec('utf8')
JsonCodec().should.be.equal(Codec('Json'))
var json2 = new JsonCodec(bufSize: 123) // # create a new JsonCodec instance, do not use singleton.
var json2.should.not.be.equal(json)
register(aClass[, aParentClass=factory[, aOptions]])
: (class method) register the aClass to your Factory Class.
Codec
is a Root Factory, we add the TextCodec
to "Codec", add the JsonTextCodec
to "TextCodec"
TextCodec
name is 'Text', JsonTextCodec
name is 'JsonText'TextCodec
name is 'Text', JsonTextCodec
name is 'Json'unregister(aName|aClass)
: (class method) unregister the class or name from the Factoryalias/aliases(aClass, aliases...)
: (class method) create aliases to the aClass.constructor(aName, aOptions)
: get a singleton instance or create a new instance item.constructor(aOptions)
: get a singleton instance or create a new instance item.
get
' method.constructor(aInstance, aOptions)
: apply(re-initialize) the aOptions to the aInstance .create(aName, aOptions)
: create a new object instanceget(aName, aOptions)
: get the singleton object instanceformatName(aName)
: format the registered name and return, defaults to same as aName. you can override this method to implement case insensitive.Factory[aName]
: get the registered class from your Factory class.getClassList(aClass)
: get the hierarchical class path list array of this aClass.path(aClass, aRootName = Factory.name)
: get the path string of this aClass factory item.pathArray(aClass, aRootName = Factory.name)
: get the path array of this aClass factory item.registeredClass(aName)
: get the registered class via name.forEach(callback)
: iterate all the singleton instances to callback.
callback
function(instance, name)These instance methods added if it is not flatOnly factory:
register(aClass[, aOptions])
: register a class to itself.unregister(aName|aClass)
: same as the unregister class method.registered(aName)
: get a singleton instance which is registered to itself.registeredClass[aName]
: get the registered class.path(aRootName = Factory.name)
: get the path string of this factory itempathArray(aRootName = Factory.name)
: get the path array of this factory itemNote: the name is case sensitive.
Factory._objects
: mark deprecated. use the Factory::_objects
insteadFactory._aliases
: mark deprecated. use the Factory::_aliases
insteadFAQs
more easily add the factory ability to your class for node and javascript
We found that custom-factory demonstrated a healthy version release cadence and project activity because the last version was released less than 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.