basant307/AI_Governance_Project
048
1"use strict";2var __defProp = Object.defineProperty;3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;4var __getOwnPropNames = Object.getOwnPropertyNames;5var __hasOwnProp = Object.prototype.hasOwnProperty;6var __export = (target, all) => {7 for (var name in all)8 __defProp(target, name, { get: all[name], enumerable: true });9};10var __copyProps = (to, from, except, desc) => {11 if (from && typeof from === "object" || typeof from === "function") {12 for (let key of __getOwnPropNames(from))13 if (!__hasOwnProp.call(to, key) && key !== except)14 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });15 }16 return to;17};18var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);19 20// src/index.ts21var src_exports = {};22__export(src_exports, {23 InvariantError: () => InvariantError,24 format: () => format,25 invariant: () => invariant26});27module.exports = __toCommonJS(src_exports);28 29// src/format.ts30var POSITIONALS_EXP = /(%?)(%([sdijo]))/g;31function serializePositional(positional, flag) {32 switch (flag) {33 case "s":34 return positional;35 case "d":36 case "i":37 return Number(positional);38 case "j":39 return JSON.stringify(positional);40 case "o": {41 if (typeof positional === "string") {42 return positional;43 }44 const json = JSON.stringify(positional);45 if (json === "{}" || json === "[]" || /^\[object .+?\]$/.test(json)) {46 return positional;47 }48 return json;49 }50 }51}52function format(message, ...positionals) {53 if (positionals.length === 0) {54 return message;55 }56 let positionalIndex = 0;57 let formattedMessage = message.replace(58 POSITIONALS_EXP,59 (match, isEscaped, _, flag) => {60 const positional = positionals[positionalIndex];61 const value = serializePositional(positional, flag);62 if (!isEscaped) {63 positionalIndex++;64 return value;65 }66 return match;67 }68 );69 if (positionalIndex < positionals.length) {70 formattedMessage += ` ${positionals.slice(positionalIndex).join(" ")}`;71 }72 formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");73 return formattedMessage;74}75 76// src/invariant.ts77var STACK_FRAMES_TO_IGNORE = 2;78function cleanErrorStack(error) {79 if (!error.stack) {80 return;81 }82 const nextStack = error.stack.split("\n");83 nextStack.splice(1, STACK_FRAMES_TO_IGNORE);84 error.stack = nextStack.join("\n");85}86var InvariantError = class extends Error {87 constructor(message, ...positionals) {88 super(message);89 this.message = message;90 this.name = "Invariant Violation";91 this.message = format(message, ...positionals);92 cleanErrorStack(this);93 }94};95var invariant = (predicate, message, ...positionals) => {96 if (!predicate) {97 throw new InvariantError(message, ...positionals);98 }99};100invariant.as = (ErrorConstructor, predicate, message, ...positionals) => {101 if (!predicate) {102 const formatMessage = positionals.length === 0 ? message : format(message, ...positionals);103 let error;104 try {105 error = Reflect.construct(ErrorConstructor, [106 formatMessage107 ]);108 } catch (err) {109 error = ErrorConstructor(formatMessage);110 }111 throw error;112 }113};114// Annotate the CommonJS export names for ESM import in node:1150 && (module.exports = {116 InvariantError,117 format,118 invariant119});120//# sourceMappingURL=index.js.map