Files
NapCatQQ/.pnpm-store/v3/files/d4/412173e6db74c25b2f84462d8d0f06fba90bc413aaebfc8bec84749f06ff6bbea8fb485cf483fbc8e2c37b993df1691b4483d339aede8d128ae34b8279d35b
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

55 lines
3.2 KiB
Plaintext

import { IsObject, IsArray, IsNumber, IsUndefined } from '../value/guard/index.mjs';
export var TypeSystemPolicy;
(function (TypeSystemPolicy) {
// ------------------------------------------------------------------
// TypeSystemPolicy: Instancing
// ------------------------------------------------------------------
/**
* Configures the instantiation behavior of TypeBox types. The `default` option assigns raw JavaScript
* references for embedded types, which may cause side effects if type properties are explicitly updated
* outside the TypeBox type builder. The `clone` option creates copies of any shared types upon creation,
* preventing unintended side effects. The `freeze` option applies `Object.freeze()` to the type, making
* it fully readonly and immutable. Implementations should use `default` whenever possible, as it is the
* fastest way to instantiate types. The default setting is `default`.
*/
TypeSystemPolicy.InstanceMode = 'default';
// ------------------------------------------------------------------
// TypeSystemPolicy: Checking
// ------------------------------------------------------------------
/** Sets whether TypeBox should assert optional properties using the TypeScript `exactOptionalPropertyTypes` assertion policy. The default is `false` */
TypeSystemPolicy.ExactOptionalPropertyTypes = false;
/** Sets whether arrays should be treated as a kind of objects. The default is `false` */
TypeSystemPolicy.AllowArrayObject = false;
/** Sets whether `NaN` or `Infinity` should be treated as valid numeric values. The default is `false` */
TypeSystemPolicy.AllowNaN = false;
/** Sets whether `null` should validate for void types. The default is `false` */
TypeSystemPolicy.AllowNullVoid = false;
/** Checks this value using the ExactOptionalPropertyTypes policy */
function IsExactOptionalProperty(value, key) {
return TypeSystemPolicy.ExactOptionalPropertyTypes ? key in value : value[key] !== undefined;
}
TypeSystemPolicy.IsExactOptionalProperty = IsExactOptionalProperty;
/** Checks this value using the AllowArrayObjects policy */
function IsObjectLike(value) {
const isObject = IsObject(value);
return TypeSystemPolicy.AllowArrayObject ? isObject : isObject && !IsArray(value);
}
TypeSystemPolicy.IsObjectLike = IsObjectLike;
/** Checks this value as a record using the AllowArrayObjects policy */
function IsRecordLike(value) {
return IsObjectLike(value) && !(value instanceof Date) && !(value instanceof Uint8Array);
}
TypeSystemPolicy.IsRecordLike = IsRecordLike;
/** Checks this value using the AllowNaN policy */
function IsNumberLike(value) {
return TypeSystemPolicy.AllowNaN ? IsNumber(value) : Number.isFinite(value);
}
TypeSystemPolicy.IsNumberLike = IsNumberLike;
/** Checks this value using the AllowVoidNull policy */
function IsVoidLike(value) {
const isUndefined = IsUndefined(value);
return TypeSystemPolicy.AllowNullVoid ? isUndefined || value === null : isUndefined;
}
TypeSystemPolicy.IsVoidLike = IsVoidLike;
})(TypeSystemPolicy || (TypeSystemPolicy = {}));