Boolean props follow the HTML presence/absence semantics.
- We stick close to standard HTML behavior: flag="false" is treated as
true in most cases. Standard bare attributes disabled and required for
form fields are interpreted as true with non-existence as false.
- The use-cases for aria-*="false" and contenteditable="false" are also
supported by typing them in the JS class as string ("true" | "false").
This "true" | "false" opt-in is types-only. At runtime it's just a
string, and strings already serialize literally and are never removed —
so the enumerated/aria path needs no runtime code.
21 lines
554 B
JavaScript
21 lines
554 B
JavaScript
/**
|
|
*
|
|
* @param value
|
|
* @param type
|
|
*/
|
|
export function deserialize(value, type) {
|
|
switch (type) {
|
|
// strict HTML boolean-attribute semantics: *any* present value is true,
|
|
// including the literal string "false" (`<el flag>`, `flag=""`,
|
|
// `flag="false"` are all true). Absence means false and is handled by the
|
|
// caller, which never reaches here with a null value.
|
|
case 'boolean':
|
|
return true
|
|
case 'number':
|
|
case 'object':
|
|
case 'undefined':
|
|
return JSON.parse(value)
|
|
default:
|
|
return value
|
|
}
|
|
}
|