UNPKG

@sudoo/marked

Version:

JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous

42 lines (41 loc) 1.35 kB
"use strict"; /** * @author WMXPY * @namespace Util * @description Option */ Object.defineProperty(exports, "__esModule", { value: true }); exports.awaitableSleep = exports.getCommentRemovedCode = exports.getRawCodeLength = exports.getRawCode = exports.getDefaultSandboxOption = void 0; const declare_1 = require("../host/declare"); const getDefaultSandboxOption = () => ({ duration: 0, maxCodeLength: 4096, maxExpression: 16384, maxForLoopLimit: 128, maxWhileLoopLimit: 128, }); exports.getDefaultSandboxOption = getDefaultSandboxOption; const getRawCode = (script) => { const rawCode = (0, exports.getCommentRemovedCode)(script) .split(declare_1.New_Line_Character) .map((str) => str.trim()) .filter((str) => Boolean(str)) .join(""); return rawCode; }; exports.getRawCode = getRawCode; const getRawCodeLength = (script) => { return (0, exports.getRawCode)(script).length; }; exports.getRawCodeLength = getRawCodeLength; const getCommentRemovedCode = (script) => { const regExp = /(\/\/.*)|(\/\*[\s\S]*?\*\/)/g; return script.replace(regExp, ""); }; exports.getCommentRemovedCode = getCommentRemovedCode; const awaitableSleep = (time) => { return new Promise((resolve) => { setTimeout(() => resolve, time); }); }; exports.awaitableSleep = awaitableSleep;