Create a fully configurable fluent interface to your DTO
Before I bore you with use-cases and details, look at these few examples:
Basic Usage
ℿ(['name', 'email']).setName('Nathaniel').setEmail('Nathaniel@website.com')
Configuring Output
ℿ(['name'], {c: {s: t => `_${t}`}})._name("Nathaniel")
Advanced Settings
const schema = ℿ(['SSN'], {ob: true}).schema
Alien (invoked via alien()
or ℿ
) is a system for building cascadable object factories. You define the properties of your object,
and it generates a fluent interface that allows the caller to chain set
commands. So, instead of:
myObject.prop1 = "Hey"
myObject.prop2 = "There"
you get:
myObject.setProp1("Hey").setProp2("There")
This is supposed to streamline your data-transfer objects.
Frankly, this design pattern is horrible for real code! This package is very much a “because it was fun to write” sort of thing. In that same spirit, 2 more design goals were accomplished here:
Let’s say you don’t like set[Property]
as the property syntax. You can pass in the setterTransformer
property to change it to _[Property]
, or changeTheValueOf[Property]To
, or whatever you want. It’s all up to the caller.
You can configure:
finalization.removeUnused
)finalization.removeSetters
)objectUtilities.schema
) (you always want this unless memory usage is a gigantic concern).reset()
that blanks the properties (objectUtilities.reset
)control.nameTransformer
)control.setterTransformer
).set({prop: 'val'})
interface (control.setObjects
)undefined
or simply don’t add them (control.createBlankProperty
)advanced.startAction
)advanced.finalAction
)advanced.stepAction
)advanced.allowUnsafeInitialization
)Any of the options are configurable with the least amount of characters to uniqueled identify the setting… (what?)
So, control.nameTransformer
can be set with {c: {n" true}}
(c = control
, n = nameTransformer
)
This is called a fast-option
in the code. In theory, it could reduce the total amount of code transmitted to a client. With that said, if it reduces your file-size in practice, something goofy is going on in your codebase!
Since I can’t know what fast-option
‘s are being used, if a change is made that may break your fast-option
, it will not bump the major semver version. Be careful! In many cases, it’s safer to use the camel-case-initialism
match.
So, {c: {nT: ''}}
for {control: {nameTransformer: ''}}