hackmud-script-manager 0.11.0 → 0.12.0-2ac9138

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. package/bin/hsm.js +55 -53
  2. package/index.js +10 -857
  3. package/package.json +11 -7
  4. package/shared.js +901 -0
  5. package/lib.js +0 -71
package/lib.js DELETED
@@ -1,71 +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.clearObject = exports.DynamicMap = 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
- function copyFilePersist(src, dest, flags) {
20
- return 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
- class DynamicMap extends Map {
47
- constructor(fallbackHandler) {
48
- super();
49
- this.fallbackHandler = fallbackHandler;
50
- }
51
- get(key) {
52
- if (super.has(key))
53
- return super.get(key);
54
- const value = this.fallbackHandler(key);
55
- super.set(key, value);
56
- return value;
57
- }
58
- }
59
- exports.DynamicMap = DynamicMap;
60
- function clearObject(object) {
61
- for (const propertyName of Object.getOwnPropertyNames(object)) {
62
- // @ts-ignore
63
- delete object[propertyName];
64
- }
65
- for (const propertySymbol of Object.getOwnPropertySymbols(object)) {
66
- // @ts-ignore
67
- delete object[propertyName];
68
- }
69
- return object;
70
- }
71
- exports.clearObject = clearObject;