astro-ghostcms/.pnpm-store/v3/files/85/0d8d184d83cd295cea46e865927...

45 lines
982 B
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
import {Info} from './info.js'
import * as types from './types.js'
/** @type {Array<keyof types>} */
// @ts-expect-error: hush.
const checks = Object.keys(types)
export class DefinedInfo extends Info {
/**
* @constructor
* @param {string} property
* @param {string} attribute
* @param {number|null} [mask]
* @param {string} [space]
*/
constructor(property, attribute, mask, space) {
let index = -1
super(property, attribute)
mark(this, 'space', space)
if (typeof mask === 'number') {
while (++index < checks.length) {
const check = checks[index]
mark(this, checks[index], (mask & types[check]) === types[check])
}
}
}
}
DefinedInfo.prototype.defined = true
/**
* @param {DefinedInfo} values
* @param {string} key
* @param {unknown} value
*/
function mark(values, key, value) {
if (value) {
// @ts-expect-error: assume `value` matches the expected value of `key`.
values[key] = value
}
}