asajs 4.0.12 → 4.0.13

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.
@@ -1,4 +1,4 @@
1
- import { RandomBindingString, ResolveBinding } from "../../components/Utils.js";
1
+ import { RandomBindingString, RandomString, ResolveBinding } from "../../components/Utils.js";
2
2
  import { bindingFuntions } from "../Configuration.js";
3
3
  import { isString } from "./Checker.js";
4
4
  export const FunctionMap = new Map();
@@ -119,25 +119,56 @@ export const defaultFunctions = {
119
119
  },
120
120
  contains: (source_str, contains_str) => {
121
121
  return {
122
- value: `(not (${source_str} - ${contains_str} = ${source_str}))`,
122
+ value: `not ((${source_str} - ${contains_str}) = ${source_str})`,
123
123
  };
124
124
  },
125
125
  starts_with: (source_str, start_str) => {
126
- const bindGenSource = RandomBindingString();
127
- if (isString(start_str))
128
- start_str = `'ASAJS_STARTS_WITH:${start_str.slice(1)}`;
129
- else
130
- start_str = `('ASAJS_STARTS_WITH:' + ${start_str})`;
131
- const { value } = defaultFunctions.contains(bindGenSource, start_str);
132
- return {
133
- genBindings: [
134
- {
135
- source: `('ASAJS_STARTS_WITH:' + ${source_str})`,
136
- target: bindGenSource,
137
- },
138
- ],
139
- value,
140
- };
126
+ const prefix = `'asajs:${RandomString(5)}:'`;
127
+ if (isString(source_str)) {
128
+ if (isString(start_str)) {
129
+ return {
130
+ value: `${source_str.slice(1, -1).startsWith(start_str.slice(1, -1))}`,
131
+ };
132
+ }
133
+ else {
134
+ source_str = prefix.slice(0, -1) + source_str.slice(1);
135
+ const start_str_bind = RandomBindingString();
136
+ return {
137
+ genBindings: [
138
+ {
139
+ source: `${prefix} + ${start_str}`,
140
+ target: start_str_bind,
141
+ },
142
+ ],
143
+ value: `not ((${source_str} - ${start_str_bind}) = ${source_str})`,
144
+ };
145
+ }
146
+ }
147
+ else {
148
+ if (isString(start_str)) {
149
+ const strLength = start_str.length - 2;
150
+ return {
151
+ value: `('%.${strLength}s' * ${source_str} = ${start_str})`,
152
+ };
153
+ }
154
+ else {
155
+ const source_str_bind = RandomBindingString();
156
+ const start_str_bind = RandomBindingString();
157
+ return {
158
+ genBindings: [
159
+ {
160
+ source: `${prefix} + ${source_str}`,
161
+ target: source_str_bind,
162
+ },
163
+ {
164
+ source: `${prefix} + ${start_str}`,
165
+ target: start_str_bind,
166
+ },
167
+ ],
168
+ value: `not ((${source_str_bind} - ${start_str_bind}) = ${source_str_bind})`,
169
+ };
170
+ }
171
+ }
141
172
  },
142
173
  /**
143
174
  * Return a translatable string
@@ -67,6 +67,9 @@ export declare const defaultFunctions: {
67
67
  value: string;
68
68
  };
69
69
  starts_with: (source_str: string, start_str: string) => {
70
+ value: string;
71
+ genBindings?: undefined;
72
+ } | {
70
73
  genBindings: {
71
74
  source: string;
72
75
  target: `#${string}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asajs",
3
- "version": "4.0.12",
3
+ "version": "4.0.13",
4
4
  "description": "Create your Minecraft JSON-UI resource packs using JavaScript",
5
5
  "keywords": [
6
6
  "Minecraft",