hackmud-script-manager 0.11.0-2c7f410 → 0.12.0-c276bb2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/hsm.js +228 -203
- package/index.d.ts +1 -1
- package/index.js +10 -718
- package/package.json +17 -7
- package/shared.js +902 -0
- package/lib.js +0 -74
package/lib.js
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.DynamicMap = exports.assert = exports.catchError = exports.stringSplice = exports.positionToLineNumber = exports.hackmudLength = exports.copyFilePersist = exports.writeFilePersist = void 0;
|
7
|
-
const path_1 = require("path");
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
9
|
-
const { writeFile, mkdir: makeDirectory, copyFile } = fs_1.default.promises;
|
10
|
-
function writeFilePersist(path, data, options) {
|
11
|
-
return writeFile(path, data, options).catch(async (error) => {
|
12
|
-
if (error.code != "ENOENT")
|
13
|
-
throw error;
|
14
|
-
await makeDirectory((0, path_1.dirname)(path), { recursive: true });
|
15
|
-
await writeFile(path, data, options);
|
16
|
-
});
|
17
|
-
}
|
18
|
-
exports.writeFilePersist = writeFilePersist;
|
19
|
-
async function copyFilePersist(src, dest, flags) {
|
20
|
-
await copyFile(src, dest, flags).catch(async (error) => {
|
21
|
-
if (error.code != "ENOENT")
|
22
|
-
throw error;
|
23
|
-
await makeDirectory((0, path_1.dirname)(dest), { recursive: true });
|
24
|
-
await copyFile(src, dest, flags);
|
25
|
-
});
|
26
|
-
}
|
27
|
-
exports.copyFilePersist = copyFilePersist;
|
28
|
-
function hackmudLength(script) {
|
29
|
-
return script.replace(/\/\/.*/g, "").replace(/[ \t\n\r\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]/g, "").length;
|
30
|
-
}
|
31
|
-
exports.hackmudLength = hackmudLength;
|
32
|
-
function positionToLineNumber(position, script) {
|
33
|
-
let totalCharacters = 0;
|
34
|
-
for (const [lineNumber, line] of script.split("\n").entries()) {
|
35
|
-
totalCharacters += line.length + 1;
|
36
|
-
if (position < totalCharacters)
|
37
|
-
return lineNumber;
|
38
|
-
}
|
39
|
-
throw new Error("unreachable");
|
40
|
-
}
|
41
|
-
exports.positionToLineNumber = positionToLineNumber;
|
42
|
-
function stringSplice(original, replacement, start, end = start) {
|
43
|
-
return original.slice(0, start) + replacement + original.slice(end);
|
44
|
-
}
|
45
|
-
exports.stringSplice = stringSplice;
|
46
|
-
async function catchError(promise) {
|
47
|
-
try {
|
48
|
-
return await promise;
|
49
|
-
}
|
50
|
-
catch (error) {
|
51
|
-
assert(error instanceof Error, "error was not an instanceof Error");
|
52
|
-
return error;
|
53
|
-
}
|
54
|
-
}
|
55
|
-
exports.catchError = catchError;
|
56
|
-
function assert(value, message = "assertion failed") {
|
57
|
-
if (!value)
|
58
|
-
throw new Error(message);
|
59
|
-
}
|
60
|
-
exports.assert = assert;
|
61
|
-
class DynamicMap extends Map {
|
62
|
-
constructor(fallbackHandler) {
|
63
|
-
super();
|
64
|
-
this.fallbackHandler = fallbackHandler;
|
65
|
-
}
|
66
|
-
get(key) {
|
67
|
-
if (super.has(key))
|
68
|
-
return super.get(key);
|
69
|
-
const value = this.fallbackHandler(key);
|
70
|
-
this.set(key, value);
|
71
|
-
return value;
|
72
|
-
}
|
73
|
-
}
|
74
|
-
exports.DynamicMap = DynamicMap;
|