generateStrictModeCheck()
generateStrictModeCheck(
objectVar,allowedKeys,ctx,customMessage?):object
Experimental
Generates code to check for extra keys in strict mode.
Parameters
objectVar: string
The variable name of the object
allowedKeys: string[]
Array of allowed property names
ctx: GeneratorContext
The generator context
customMessage?: string
Optional custom error message
Returns: object
Generated code lines and updated context
code: string[]
ctx: GeneratorContext
Since
2.0.0
Example
const result = generateStrictModeCheck("value", ["name", "age"], ctx);
// result.code = [
// 'for (var k in value) {',
// ' if (Object.prototype.hasOwnProperty.call(value, k)) {',
// ' if (k !== "name" && k !== "age") return "Unexpected property: " + k;',
// ' }',
// '}'
// ]