Further restrictions and transformations can be defined on a PType when it is called as a function. When
a PType is extended in this manner, it is still of the same type. It retains the same name and does not
appear in the OpenAPI docs -- unless restriction-properties have been set
(see PTArgs for more details):
PT.Text = new PType({
name: 'Text', type: 'String',
sanitizers(v) {
return (!!!v || v===undefined ?
"" : v.toString().replace(/'/g,"\\'")
);
}
});
console.log(PT.Text.sanitize('hello, world')); // "hello, world"
console.log(PT.Text.sanitize(null)); // ""
// Further-customize by Calling the PType as a Function
let PT_TxtToArr = PT.Text({ selects: ["hello","world"] });
// Prints
console.log(PT_TxtToArr.sanitize('world')); // "world"
console.log(PT_TxtToArr.sanitize('noice')); // ""
console.log(PT_TxtToArr.sanitize('hello, world')); // ""
A customized version of the PType.
Creates a new PType, which serves as the definition of a Request-Parameter Type.
// Singular Sanitizer
new PType({ name: "", type: "", sanitizers(v) {...}, iterable: true });
See: PTOpts.name.
See: PTOpts.type.
See: PTOpts.sanitizers.
See: PTOpts.iterable.
A new PType.
Creates a new PType, which serves as the definition of a Request-Parameter Type.
// Multiple sanitizers, ran in succession
new PType({
name: "", type: "", sanitizers: [
(v) => (...),
(v) => (...),
(v) => (...),
],
});
A new PType.
A collection of all of the CFG.PNTS.PTOpts.sanitizers defined for this PType.
Performs each of the sanitizers and any PTArg
transformations that have been defined for a particular PType.
A parameter value froma Client request.
The sanitized value.
Extends the current PType, producing a new one with and different name and
other modifications. When a PType is extended, it becomes a new param-type and will be included in the
OpenAPI docs (see PTOpts for more details).
// Type-checks for Array<String>
PT.L.ArrStr = new PType({
name: "StrArray", type: "String",
sanitizers(v) { return v.constructor.name===this.type; },
iterable: true
});
// Type-checks for Array<Number>
PT.L.ArrNum = ArrStr.extend({
name: "NumArray", type: "Number"
});
The brand-new PType.
Like the constructor, the extend function can also define an
Array of sanitizers in the PTOpts
argument.
Cycles through the sanitization processes
The value to sanitze
The sanitized value
A Unique-Identifier for the Type.
Add a Type-Name to the Unique-Identifier.
A default-value. If set, will assume a Type-Name is needed.
The unique identifier.
A OpenAPI-compliant version of a PType.
(new PType({
name: 'TwoNumbers', type: 'Number',
iterable: true, sanitizers(v) { ... }
})({
min: 0, max: 2, slice: [0,2]
}).toDoc() === {
type: "array",
items: {
type: "integer",
minimum: 1
},
minItems: 0,
maxItems: 2
});
Determines whether the given value inherits from this function if this function was used as a constructor function.
A constructor function can control which objects are recognized as its instances by 'instanceof' by overriding this method.
Calls the PType, substituting the specified object for the this value of the PType, and the specified array for the arguments of the PType.
The object to be used as the this object.
A set of arguments to be passed to the function.
Calls a method of a PType, substituting another PType for the current PType.
The object to be used as the current object.
A list of arguments to be passed to the method.
Calls the PType, substituting the specified object for the this value of the PType, and the specified array for the arguments of the PType.
An object to which the this keyword can refer inside the new function.
A list of arguments to be passed to the new function.
This
classis used to define reusableParamTypeswhich arerequredin the Descr definitions (specifically, the Descr.type property).