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;',
// ' }',
// '}'
// ]