normalize-function-arguments
v0.2.0
Published
Normalize JavaScript function arguments to simplify variadic function signatures, default values, type validation
Readme
normalize-function-arguments
Table of Contents generated with DocToc
normalize-function-arguments
Normalize JavaScript function arguments to simplify variadic function signatures, default values, type validation
Properties
- method
nfa()accepts (among other things) a functionfnas argument nfa()returns a function (call itnfn), which is a wrapped version offnthat- accepts the same number of arguments;
fnwill be called with a normalized arguments- and its return value will be returned by the wrapper.
- The declaration of
fn:- must not use spread syntax or default values on any on the parameters
- must have a parameter named
cfgas its only, or as its last or as its next-to-last parameter
- (TBD) normalization of call-time arguments
- (TBD) templating
- (TBD) validation
- (TBD) ClearType integration
Terminology
- qualified parameters (
Q) - qualified argument(s)
- positional parameters (
P) - positional arguments
To Do
Template Class
- class
Templateacceptscfg, an optional, single POD for instantiation - will copy all own properties of
cfg, but - properties that are functions will be turned into managed properties
- in order to have templates with mutable objects as properties that are not shared after copying with
t = new Template cfg; { t..., }, do not uset = { n: [ 1, 2, 3, ], }, instead wrap value in function, as int = { n: ( -> [ 1, 2, 3, ] ), }; now every timetis copied,t.nwill be a new list - nested PODs will be recursively turned into instances of
Template
Order of Arguments
- when CFG is in the penultimate, an optional function is assumed to be the last parameter
- in such cases, when the wrapped function is called with a function as last argument, that function will be 'shifted' to the position of the terminal parameter, meaning that it will not be understood as the value of another positional argument
Other
[—]integrate ClearType asnfa type, fnandnfa { type, }, fn[—]allow shifting of arguments depending on their type[—]configuration settings:[—]demand vs allow final CFG[—]demand n positional arguments[+]fallback value for unset qualified arguments (template)[+]function or type to check whether last argument is 'Q-worthy' (one expected for named arguments)[—]name of named parameters object (defaults tocfg)[—]allow both standalonetype(as innfa type ( cfg ) ->) andtypeas named setting (as innfa { type, } ( cfg ) ->)
- resolution strategy for repeated setting:
[—]cfg.templateshould prevail incfg = { template, type: { template, }, }[—]cfg.isashould prevail incfg = { isa, type: { isa, }, }[—]cfg.validateshould prevail incfg = { validate, type: { validate, }, }[—]cfg.validateshould prevail incfg = { validate, isa, type: { validate, isa, }, }- in general, the 'lower'/outer, ('more visible') setting should prevail; explicit
validate()should prevail over implicit validation constructed fromisa()
[—]allow the CFG parameter to be in penultimate position to cover cases (like inNormalize_function_arguments::nfa()) where a final parameter should be occupied by e.g. a function (but do not place type restrictions on that last parameter)[—]allow asynchronous functions, generator functions, async generator functions forNormalize_function_arguments::nfa#fn[—]errors:[—]refactor error classes to proper module[—]use standard setup[—]apply to errors thrown in submodulehelpers
[—]implement a 'nano' or 'kernel' version of ClearType (sanscreate()prob.) but, crucially, with constructor forvalidate()methods, propertype_of()
Is Done
[+]handle empty signatures[+]inNormalize_function_arguments::get_signature()[+]inNormalize_function_arguments::nfa()
[+]consider to dump dispositions, disallow soaks, default values in signatures to make analysis simpler, faster; will be handled bycfg.template/cfg.type[+]implement classTemplate[+]implement recursive templating in classTemplate[+]if last parameter is namedcfg, assume it is for the named parameters object and assign it a fallback value{}mandate at least one and final parameter that must have the configuredq_name[+]CFG settingtemplateasnfa { template, }, fn[+]preserve name of wrapped function[+]implement validation asnfa { isa, }, fn
Don't
[—]name clash resolution strategies positional arguments other thanundefinedalways override values incfg[—]fallback value for unset positional arguments (or usetemplate) positional arguments other thanundefinedalways override values incfg
