asajs 4.1.1 → 4.1.2-indev

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.
@@ -38,13 +38,13 @@ if (!fs.existsSync("asajs.config.js")) {
38
38
 
39
39
  return \`#$\{out.join("")}\`
40
40
  }\n`,
41
- fs.readFileSync("resources/asajs.config.js", "utf-8").replace("asajs/", "./"),
41
+ fs.readFileSync("resources/example-config.js", "utf-8").replace("asajs/", "./"),
42
42
  ].join("\n"));
43
43
  }
44
44
  else {
45
45
  fs.writeFileSync("asajs.config.js", [
46
46
  'import { RandomBindingString } from "asajs"\n',
47
- fs.readFileSync("node_modules/asajs/resources/asajs.config.js", "utf-8"),
47
+ fs.readFileSync("node_modules/asajs/resources/example-config.js", "utf-8"),
48
48
  ].join("\n"));
49
49
  }
50
50
  }
@@ -22,6 +22,12 @@ export function isCompileBinding(input) {
22
22
  export function isHasBinding(input) {
23
23
  return /#\w+/.test(input);
24
24
  }
25
+ export function isBinding(input) {
26
+ return /^#\w+$/.test(input);
27
+ }
28
+ export function isNumber(input) {
29
+ return /^[+-]?(?:\d+|\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(input);
30
+ }
25
31
  export function isString(input) {
26
32
  return /^'.+'$/.test(input);
27
33
  }
@@ -1,6 +1,6 @@
1
1
  import { RandomBindingString, RandomString, ResolveBinding } from "../../components/Utils.js";
2
2
  import { bindingFuntions } from "../Configuration.js";
3
- import { isString } from "./Checker.js";
3
+ import { isBinding, isNumber, isString } from "./Checker.js";
4
4
  export const FunctionMap = new Map();
5
5
  export const defaultFunctions = {
6
6
  /**
@@ -117,6 +117,11 @@ export const defaultFunctions = {
117
117
  value: count,
118
118
  };
119
119
  },
120
+ not_contains: (source_str, contains_str) => {
121
+ return {
122
+ value: `(${source_str} - ${contains_str}) = ${source_str}`,
123
+ };
124
+ },
120
125
  contains: (source_str, contains_str) => {
121
126
  return {
122
127
  value: `not ((${source_str} - ${contains_str}) = ${source_str})`,
@@ -170,6 +175,47 @@ export const defaultFunctions = {
170
175
  }
171
176
  }
172
177
  },
178
+ str_slice: (str, start, end) => {
179
+ const prefix = `'asajs:${RandomString(5)}:'`;
180
+ const genStrBinds = {
181
+ source: ``,
182
+ target: RandomBindingString(),
183
+ };
184
+ if (isBinding(str))
185
+ genStrBinds.source = `(${prefix} + ${str})`;
186
+ else if (isString(str))
187
+ genStrBinds.source = `${prefix.slice(0, -1)}${str.slice(1)}`;
188
+ else
189
+ throw new Error("Invalid str");
190
+ if (isBinding(start))
191
+ start = `('%.' + (${prefix.length - 2} + ${start}) + 's')`;
192
+ else if (isNumber(start))
193
+ start = `'%.${+start + prefix.length - 2}s'`;
194
+ else
195
+ throw new Error("Invalid start");
196
+ if (end) {
197
+ if (isBinding(end))
198
+ end = `('%.' + (${prefix.length - 2} + ${end}) + 's')`;
199
+ else if (isNumber(end))
200
+ end = `'%.${+end + prefix.length - 2}s'`;
201
+ else
202
+ throw new Error("Invalid end");
203
+ const sliceEnd = {
204
+ source: `(${end} * ${genStrBinds.target})`,
205
+ target: RandomBindingString(),
206
+ };
207
+ return {
208
+ genBindings: [genStrBinds, sliceEnd],
209
+ value: `${sliceEnd.target} - (${start} * ${sliceEnd.target})`,
210
+ };
211
+ }
212
+ else {
213
+ return {
214
+ genBindings: [genStrBinds],
215
+ value: `${genStrBinds.target} - (${start} * ${genStrBinds.target})`,
216
+ };
217
+ }
218
+ },
173
219
  /**
174
220
  * Return a translatable string
175
221
  * @param key
@@ -6,4 +6,6 @@ export declare function isBinaryChar(char: string): boolean;
6
6
  export declare function isOctalChar(char: string): boolean;
7
7
  export declare function isCompileBinding(input: string): boolean;
8
8
  export declare function isHasBinding(input: string): boolean;
9
+ export declare function isBinding(input: string): boolean;
10
+ export declare function isNumber(input: string): boolean;
9
11
  export declare function isString(input: string): boolean;
@@ -63,6 +63,9 @@ export declare const defaultFunctions: {
63
63
  }[];
64
64
  value: `#${string}`;
65
65
  };
66
+ not_contains: (source_str: string, contains_str: string) => {
67
+ value: string;
68
+ };
66
69
  contains: (source_str: string, contains_str: string) => {
67
70
  value: string;
68
71
  };
@@ -76,6 +79,10 @@ export declare const defaultFunctions: {
76
79
  }[];
77
80
  value: string;
78
81
  };
82
+ str_slice: (str: string, start: string, end: string) => {
83
+ genBindings: GenBinding[];
84
+ value: string;
85
+ };
79
86
  /**
80
87
  * Return a translatable string
81
88
  * @param key
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asajs",
3
- "version": "4.1.1",
3
+ "version": "4.1.2-indev",
4
4
  "description": "Create your Minecraft JSON-UI resource packs using JavaScript",
5
5
  "keywords": [
6
6
  "Minecraft",
package/asajs.config.js DELETED
@@ -1,51 +0,0 @@
1
- export function RandomBindingString(length, base = 32) {
2
- const chars = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, base)
3
- const out = new Array()
4
-
5
- try {
6
- const buffer = new Uint8Array(length)
7
- crypto.getRandomValues(buffer)
8
- for (let i = 0; i < length; i++) {
9
- out[i] = chars[buffer[i] % base]
10
- }
11
- } catch {
12
- for (let i = 0; i < length; i++) {
13
- out[i] = chars[Math.floor(Math.random() * base)]
14
- }
15
- }
16
-
17
- return `#${out.join("")}`
18
- }
19
-
20
- /**
21
- * Configuration object for the AsaJS build process.
22
- * @type {import('./config.d.ts').Config}
23
- */
24
- export const config = {
25
- packinfo: {
26
- name: "AsaJS",
27
- description: "Create your Minecraft JSON-UI resource packs using JavaScript.",
28
- version: [1, 0, 0],
29
- },
30
- compiler: {
31
- enabled: true,
32
- autoImport: true,
33
- autoEnable: true,
34
- importToPreview: false,
35
- },
36
- binding_functions: {
37
- custom_abs: function (number) {
38
- const randomAbs = RandomBindingString(16)
39
-
40
- return {
41
- generate_bindings: [
42
- {
43
- source_property_name: `[ abs(${number}) ]`,
44
- target_property_name: randomAbs,
45
- },
46
- ],
47
- return_value: randomAbs,
48
- }
49
- },
50
- },
51
- }