@mirascript/mirascript 0.1.50 → 0.1.53
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/dist/{chunk-DQKJPXKQ.js → chunk-UQXOYRJI.js} +221 -47
- package/dist/chunk-UQXOYRJI.js.map +6 -0
- package/dist/index.js +1 -1
- package/dist/subtle.js +1 -1
- package/dist/vm/lib/global/index.d.ts +1 -1
- package/dist/vm/lib/global/index.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/index.d.ts +2 -0
- package/dist/vm/lib/global/sequence/index.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/new.d.ts +4 -0
- package/dist/vm/lib/global/sequence/new.d.ts.map +1 -0
- package/dist/vm/lib/global/sequence/sort.d.ts +1 -1
- package/dist/vm/lib/global/sequence/sort.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/unique.d.ts +4 -0
- package/dist/vm/lib/global/sequence/unique.d.ts.map +1 -0
- package/dist/vm/lib/global/string/case.d.ts +3 -0
- package/dist/vm/lib/global/string/case.d.ts.map +1 -0
- package/dist/vm/lib/global/string/index.d.ts +8 -0
- package/dist/vm/lib/global/string/index.d.ts.map +1 -0
- package/dist/vm/lib/global/string/search.d.ts +4 -0
- package/dist/vm/lib/global/string/search.d.ts.map +1 -0
- package/dist/vm/lib/global/string/trim.d.ts +4 -0
- package/dist/vm/lib/global/string/trim.d.ts.map +1 -0
- package/dist/vm/operations/compound.d.ts.map +1 -1
- package/dist/vm/operations/type-check.d.ts +2 -2
- package/dist/vm/operations/type-check.d.ts.map +1 -1
- package/dist/vm/types/extern.d.ts +2 -2
- package/dist/vm/types/extern.d.ts.map +1 -1
- package/dist/vm/types/index.d.ts +1 -1
- package/dist/vm/types/index.d.ts.map +1 -1
- package/dist/vm/types/module.d.ts +2 -2
- package/dist/vm/types/module.d.ts.map +1 -1
- package/dist/vm/types/wrapper.d.ts +2 -2
- package/dist/vm/types/wrapper.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/vm/lib/global/index.ts +1 -1
- package/src/vm/lib/global/sequence/index.ts +2 -0
- package/src/vm/lib/global/sequence/new.ts +48 -0
- package/src/vm/lib/global/sequence/sort.ts +6 -6
- package/src/vm/lib/global/sequence/unique.ts +95 -0
- package/src/vm/lib/global/sequence/with.ts +1 -1
- package/src/vm/lib/global/string/case.ts +27 -0
- package/src/vm/lib/global/string/index.ts +65 -0
- package/src/vm/lib/global/string/search.ts +39 -0
- package/src/vm/lib/global/string/trim.ts +40 -0
- package/src/vm/operations/compound.ts +14 -5
- package/src/vm/operations/type-check.ts +3 -3
- package/src/vm/types/extern.ts +2 -2
- package/src/vm/types/index.ts +1 -1
- package/src/vm/types/module.ts +2 -2
- package/src/vm/types/wrapper.ts +2 -2
- package/dist/chunk-DQKJPXKQ.js.map +0 -6
- package/dist/vm/lib/global/string.d.ts +0 -11
- package/dist/vm/lib/global/string.d.ts.map +0 -1
- package/src/vm/lib/global/string.ts +0 -138
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { VmArray, VmRecord } from '../../../types/index.js';
|
|
2
|
+
export declare const new_record: ((size: import("../../../types/index.js").VmValue | undefined, generator: import("../../../types/index.js").VmValue | undefined) => VmRecord) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
3
|
+
export declare const new_array: ((length: import("../../../types/index.js").VmValue | undefined, generator: import("../../../types/index.js").VmValue | undefined) => VmArray) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
4
|
+
//# sourceMappingURL=new.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new.d.ts","sourceRoot":"","sources":["../../../../../src/vm/lib/global/sequence/new.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAW,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAO1E,eAAO,MAAM,UAAU,sIACA,QAAQ,iEAoB9B,CAAC;AAEF,eAAO,MAAM,SAAS,wIACG,OAAO,iEAgB/B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { VmConst, VmValue } from '../../../types/index.js';
|
|
2
2
|
export declare const sort: ((data: VmValue | undefined, comparator: VmValue | undefined) => VmConst[]) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
3
|
-
export declare const sort_by: ((data: VmValue | undefined,
|
|
3
|
+
export declare const sort_by: ((data: VmValue | undefined, key: VmValue | undefined, comparator: VmValue | undefined) => VmConst[]) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
4
4
|
//# sourceMappingURL=sort.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../../../../src/vm/lib/global/sequence/sort.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAS,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AA+BvE,eAAO,MAAM,IAAI,6IAwBhB,CAAC;AAEF,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../../../../src/vm/lib/global/sequence/sort.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAS,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AA+BvE,eAAO,MAAM,IAAI,6IAwBhB,CAAC;AAEF,eAAO,MAAM,OAAO,uKAgCnB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { VmConst, VmValue } from '../../../types/index.js';
|
|
2
|
+
export declare const unique: ((data: VmValue | undefined, equal: VmValue | undefined) => VmConst[]) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
3
|
+
export declare const unique_by: ((data: VmValue | undefined, key: VmValue | undefined, equal: VmValue | undefined) => VmConst[]) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
4
|
+
//# sourceMappingURL=unique.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unique.d.ts","sourceRoot":"","sources":["../../../../../src/vm/lib/global/sequence/unique.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAS,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAkBvE,eAAO,MAAM,MAAM,wIA8BlB,CAAC;AAEF,eAAO,MAAM,SAAS,kKAyCrB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const to_uppercase: ((str: import("../../../index.js").VmValue | undefined) => string) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
2
|
+
export declare const to_lowercase: ((str: import("../../../index.js").VmValue | undefined) => string) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
3
|
+
//# sourceMappingURL=case.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"case.d.ts","sourceRoot":"","sources":["../../../../../src/vm/lib/global/string/case.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,oIAWxB,CAAC;AAEF,eAAO,MAAM,YAAY,oIAWxB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './trim.js';
|
|
2
|
+
export * from './case.js';
|
|
3
|
+
export * from './search.js';
|
|
4
|
+
export declare const chars: ((str: import("../../../index.js").VmValue | undefined) => string[]) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
5
|
+
export declare const replace: ((str: import("../../../index.js").VmValue | undefined, search: import("../../../index.js").VmValue | undefined, replacement?: import("../../../index.js").VmValue | undefined) => string) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
6
|
+
export declare const split: ((str: import("../../../index.js").VmValue | undefined, separator?: import("../../../index.js").VmValue | undefined) => string[]) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
7
|
+
export declare const join: ((arr: import("../../../index.js").VmValue | undefined, separator?: import("../../../index.js").VmValue | undefined) => string) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/vm/lib/global/string/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAE5B,eAAO,MAAM,KAAK,sIAWjB,CAAC;AAEF,eAAO,MAAM,OAAO,4PAcnB,CAAC;AAEF,eAAO,MAAM,KAAK,mMAcjB,CAAC;AAEF,eAAO,MAAM,IAAI,iMAahB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const starts_with: ((str: import("../../../index.js").VmValue | undefined, search: import("../../../index.js").VmValue | undefined) => boolean) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
2
|
+
export declare const ends_with: ((str: import("../../../index.js").VmValue | undefined, search: import("../../../index.js").VmValue | undefined) => boolean) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
3
|
+
export declare const contains: ((str: import("../../../index.js").VmValue | undefined, search: import("../../../index.js").VmValue | undefined) => boolean) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
4
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../../../src/vm/lib/global/string/search.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,8LAWvB,CAAC;AACF,eAAO,MAAM,SAAS,8LAWrB,CAAC;AAEF,eAAO,MAAM,QAAQ,8LAWpB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const trim_start: ((str: import("../../../index.js").VmValue | undefined) => string) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
2
|
+
export declare const trim_end: ((str: import("../../../index.js").VmValue | undefined) => string) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
3
|
+
export declare const trim: ((str: import("../../../index.js").VmValue | undefined) => string) & import("../../helpers.js").VmLibOption & Record<never, never>;
|
|
4
|
+
//# sourceMappingURL=trim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trim.d.ts","sourceRoot":"","sources":["../../../../../src/vm/lib/global/string/trim.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,oIAWtB,CAAC;AAEF,eAAO,MAAM,QAAQ,oIAWpB,CAAC;AAEF,eAAO,MAAM,IAAI,oIAWhB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compound.d.ts","sourceRoot":"","sources":["../../../src/vm/operations/compound.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compound.d.ts","sourceRoot":"","sources":["../../../src/vm/operations/compound.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAS3E,mBAAmB;AACnB,wBAAgB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,GAAG,OAAO,CAoB1D;AAED,aAAa;AACb,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAO5C;AAED,iBAAiB;AACjB,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,QAAQ,CAarF;AAED,iBAAiB;AACjB,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,QAAQ,CAWpF;AACD,eAAe;AACf,wBAAgB,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAMpD;AAED,WAAW;AACX,wBAAgB,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAuBpD;AACD,WAAW;AACX,wBAAgB,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAO/D;AACD,cAAc;AACd,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC,CAMrE;AACD,WAAW;AACX,wBAAgB,aAAa,CAAC,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,IAAI,CAuB5D;AAED,WAAW;AACX,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC,CAqBxE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { VmTypeName, VmAny, VmArray, VmRecord, VmValue } from '../types/index.js';
|
|
2
2
|
/** 获取值的类型名称 */
|
|
3
|
-
export declare function $Type(value: VmAny):
|
|
3
|
+
export declare function $Type(value: VmAny): VmTypeName;
|
|
4
4
|
/** 判断值是否为布尔值 */
|
|
5
5
|
export declare function $IsBoolean(value: VmAny): value is boolean;
|
|
6
6
|
/** 判断值是否为数字 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-check.d.ts","sourceRoot":"","sources":["../../../src/vm/operations/type-check.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"type-check.d.ts","sourceRoot":"","sources":["../../../src/vm/operations/type-check.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGvF,eAAe;AACf,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,CAO9C;AACD,gBAAgB;AAChB,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,OAAO,CAGzD;AACD,eAAe;AACf,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,MAAM,CAGvD;AACD,gBAAgB;AAChB,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,MAAM,CAGvD;AACD,eAAe;AACf,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,QAAQ,CAGzD;AACD,eAAe;AACf,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,OAAO,CAGvD;AACD,eAAe;AACf,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,KAAK,IAAI,WAAW,CAAC,CAAC,CAAC,CAItG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { VmTypeName, VmAny, VmConst, VmPrimitive, VmValue } from './index.js';
|
|
2
2
|
import { VmWrapper } from './wrapper.js';
|
|
3
3
|
/** 包装 Mirascript `extern` 类型的对象 */
|
|
4
4
|
export declare class VmExtern<const T extends object = object> extends VmWrapper<T> {
|
|
@@ -37,7 +37,7 @@ export declare class VmExtern<const T extends object = object> extends VmWrapper
|
|
|
37
37
|
/** @inheritdoc */
|
|
38
38
|
toString(useBraces: boolean): string;
|
|
39
39
|
/** @inheritdoc */
|
|
40
|
-
get type():
|
|
40
|
+
get type(): VmTypeName;
|
|
41
41
|
/** @inheritdoc */
|
|
42
42
|
get tag(): string;
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extern.d.ts","sourceRoot":"","sources":["../../../src/vm/types/extern.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"extern.d.ts","sourceRoot":"","sources":["../../../src/vm/types/extern.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AA4BzC,mCAAmC;AACnC,qBAAa,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAInE,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,IAAI;;IAH7C,UAAU;IACV,KAAK,EAAE,CAAC;IACR,uCAAuC;IAC9B,OAAO,GAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,IAAW;IAKxD;;;OAGG;IACH,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO;IAiBrD,kBAAkB;IAClB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,KAAK,IAAI,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC;IAI9F,kBAAkB;IACT,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAGlC,kBAAkB;IACT,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAMhC,mCAAmC;IACnC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO;IAMzC,wBAAwB;IACxB,IAAI,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,KAAK;IAerC,kBAAkB;IACT,IAAI,CAAC,oBAAoB,UAAQ,GAAG,MAAM,EAAE;IAmBrD,kBAAkB;IACT,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAIpC;;;;OAIG;IACH,WAAW,IAAI,IAAI,IAAI,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAGnD,kBAAkB;IACT,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM;IAoB7C,kBAAkB;IAClB,IAAa,IAAI,IAAI,UAAU,CAE9B;IACD,kBAAkB;IAClB,IAAa,GAAG,IAAI,MAAM,CA6BzB;CACJ"}
|
package/dist/vm/types/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { VmExtern } from './extern.js';
|
|
|
2
2
|
import type { VmFunction } from './function.js';
|
|
3
3
|
import type { VmModule } from './module.js';
|
|
4
4
|
/** 类型名称 */
|
|
5
|
-
export type
|
|
5
|
+
export type VmTypeName = keyof VmValueMap;
|
|
6
6
|
/** Mirascript 虚拟机内的未初始化变量 */
|
|
7
7
|
export type VmUninitialized = undefined;
|
|
8
8
|
/** Mirascript 原始值 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vm/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,WAAW;AACX,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vm/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,WAAW;AACX,MAAM,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC;AAE1C,6BAA6B;AAC7B,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC;AACxC,qBAAqB;AACrB,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAC3D;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;AACzD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG;IACnB,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;CAC/C,CAAC;AACF,2BAA2B;AAC3B,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AACvD,2BAA2B;AAC3B,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAC;AAC1D,0BAA0B;AAC1B,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,QAAQ,CAAC;AAC7C,kCAAkC;AAClC,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,eAAe,CAAC;AAE9C,aAAa;AACb,MAAM,WAAW,UAAU;IACvB,SAAS;IACT,GAAG,EAAE,IAAI,CAAC;IACV,UAAU;IACV,MAAM,EAAE,MAAM,CAAC;IACf,SAAS;IACT,MAAM,EAAE,MAAM,CAAC;IACf,UAAU;IACV,OAAO,EAAE,OAAO,CAAC;IACjB,oBAAoB;IACpB,MAAM,EAAE,QAAQ,CAAC;IACjB,oBAAoB;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,oBAAoB;IACpB,QAAQ,EAAE,UAAU,CAAC;IACrB,aAAa;IACb,MAAM,EAAE,QAAQ,CAAC;IACjB,oBAAoB;IACpB,MAAM,EAAE,QAAQ,CAAC;CACpB;AAED,OAAO,EACH,OAAO,EACP,SAAS,EACT,mBAAmB,EACnB,4BAA4B,EAC5B,yBAAyB,EACzB,YAAY,EACZ,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EACV,aAAa,EACb,UAAU,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,iBAAiB,GACpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,eAAe,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3G,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC5G,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { VmTypeName, VmAny, VmImmutable } from './index.js';
|
|
2
2
|
import { VmWrapper } from './wrapper.js';
|
|
3
3
|
/** Mirascript 模块 */
|
|
4
4
|
export declare class VmModule<const T extends Record<string, VmImmutable> = Record<string, VmImmutable>> extends VmWrapper<T> {
|
|
@@ -18,7 +18,7 @@ export declare class VmModule<const T extends Record<string, VmImmutable> = Reco
|
|
|
18
18
|
/** @inheritdoc */
|
|
19
19
|
same(other: VmAny): boolean;
|
|
20
20
|
/** @inheritdoc */
|
|
21
|
-
get type():
|
|
21
|
+
get type(): VmTypeName;
|
|
22
22
|
/** @inheritdoc */
|
|
23
23
|
get tag(): string;
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/vm/types/module.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/vm/types/module.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,oBAAoB;AACpB,qBAAa,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAE7G,WAAW;IACX,QAAQ,CAAC,IAAI,EAAE,MAAM;;IADrB,WAAW;IACF,IAAI,EAAE,MAAM;IACrB,WAAW;IACX,KAAK,EAAE,CAAC;IAIZ,kBAAkB;IACT,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAGlC,kBAAkB;IACT,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAIhC,kBAAkB;IACT,IAAI,IAAI,MAAM,EAAE;IAGzB,kBAAkB;IACT,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAGpC,kBAAkB;IAClB,IAAa,IAAI,IAAI,UAAU,CAE9B;IACD,kBAAkB;IAClB,IAAa,GAAG,IAAI,MAAM,CAEzB;CACJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { VmTypeName, VmAny } from './index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Mirascript 特殊值的包装器
|
|
4
4
|
*/
|
|
@@ -14,7 +14,7 @@ export declare abstract class VmWrapper<T extends object> {
|
|
|
14
14
|
/** 与其他值比较 */
|
|
15
15
|
abstract same(other: VmAny): boolean;
|
|
16
16
|
/** 获取类型 */
|
|
17
|
-
abstract get type():
|
|
17
|
+
abstract get type(): VmTypeName;
|
|
18
18
|
/** 获取当前对象的描述 */
|
|
19
19
|
abstract get tag(): string;
|
|
20
20
|
/** 描述键对应的值 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../../../src/vm/types/wrapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../../../src/vm/types/wrapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEpD;;GAEG;AACH,8BAAsB,SAAS,CAAC,CAAC,SAAS,MAAM;IAChC,QAAQ,CAAC,KAAK,EAAE,CAAC;gBAAR,KAAK,EAAE,CAAC;IAC7B,cAAc;IACd,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAClC,cAAc;IACd,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAChC,WAAW;IACX,QAAQ,CAAC,IAAI,IAAI,MAAM,EAAE;IACzB,aAAa;IACb,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IACpC,WAAW;IACX,QAAQ,KAAK,IAAI,IAAI,UAAU,CAAC;IAChC,gBAAgB;IAChB,QAAQ,KAAK,GAAG,IAAI,MAAM,CAAC;IAC3B,cAAc;IACd,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAGzC,YAAY;IACZ,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM;CAKvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirascript/mirascript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.53",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "An expression based scripting language.",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"@cloudpss/worker": "^0.1.10",
|
|
30
30
|
"source-map-js": "^1.2.1",
|
|
31
31
|
"supports-color": "^10.2.2",
|
|
32
|
-
"@mirascript/bindings": "~0.1.
|
|
33
|
-
"@mirascript/constants": "~0.1.
|
|
32
|
+
"@mirascript/bindings": "~0.1.53",
|
|
33
|
+
"@mirascript/constants": "~0.1.53"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^25.
|
|
37
|
-
"ava": "^
|
|
36
|
+
"@types/node": "^25.4.0",
|
|
37
|
+
"ava": "^7.0.0",
|
|
38
38
|
"c8": "^11.0.0",
|
|
39
39
|
"tinybench": "^6.0.0",
|
|
40
40
|
"type-fest": "^5.4.4"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { VmArray, VmConst, VmRecord } from '../../../types/index.js';
|
|
2
|
+
import { toString } from '../../../../helpers/convert/to-string.js';
|
|
3
|
+
import { VM_ARRAY_MAX_LENGTH } from '../../../../helpers/constants.js';
|
|
4
|
+
import { keys as _keys, values as _values, entries as _entries, PositiveInfinity } from '../../../../helpers/utils.js';
|
|
5
|
+
import { $Call, $El, $Get } from '../../../operations/index.js';
|
|
6
|
+
import { VmLib, expectCallable, expectIntegerRange } from '../../helpers.js';
|
|
7
|
+
|
|
8
|
+
export const new_record = VmLib(
|
|
9
|
+
(size, generator): VmRecord => {
|
|
10
|
+
const n = expectIntegerRange('size', size, 0, PositiveInfinity);
|
|
11
|
+
expectCallable('generator', generator, null);
|
|
12
|
+
const result: Record<string, VmConst> = {};
|
|
13
|
+
for (let i = 0; i < n; i++) {
|
|
14
|
+
const entry = $Call(generator, [i]) as VmArray;
|
|
15
|
+
if (entry == null) continue;
|
|
16
|
+
const key = $Get(entry, 0);
|
|
17
|
+
const value = $El($Get(entry, 1));
|
|
18
|
+
result[toString(key)] = value;
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
summary: '根据生成器函数创建一个记录',
|
|
24
|
+
params: { size: '记录的大小', generator: '生成器函数,返回键值对或 nil(表示跳过该条目)' },
|
|
25
|
+
paramsType: { size: 'number', generator: 'fn(index: number) -> (string, any) | nil' },
|
|
26
|
+
returnsType: 'record',
|
|
27
|
+
examples: ['new_record(3, fn { (it, it * 2) }) // (0, 2, 4)'],
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export const new_array = VmLib(
|
|
32
|
+
(length, generator): VmArray => {
|
|
33
|
+
const n = expectIntegerRange('length', length, 0, VM_ARRAY_MAX_LENGTH);
|
|
34
|
+
expectCallable('generator', generator, null);
|
|
35
|
+
const result: VmConst[] = [];
|
|
36
|
+
for (let i = 0; i < n; i++) {
|
|
37
|
+
result.push($El($Call(generator, [i])));
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
summary: '根据生成器函数创建一个数组',
|
|
43
|
+
params: { length: '数组的长度', generator: '生成器函数,返回数组元素的值' },
|
|
44
|
+
paramsType: { length: 'number', generator: 'fn(index: number) -> any' },
|
|
45
|
+
returnsType: 'array',
|
|
46
|
+
examples: ['new_array(5, fn { it * it }) // [0, 1, 4, 9, 16]'],
|
|
47
|
+
},
|
|
48
|
+
);
|
|
@@ -27,7 +27,7 @@ function cmp(comparator: VmAny, recovered: VmValue): typeof defaultCompare {
|
|
|
27
27
|
expectCallable('comparator', comparator, recovered);
|
|
28
28
|
return (a: VmValue = null, b: VmValue = null) => {
|
|
29
29
|
const ret = $Call(comparator, [a, b]);
|
|
30
|
-
return toNumber(ret,
|
|
30
|
+
return toNumber(ret, undefined);
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -58,9 +58,9 @@ export const sort = VmLib(
|
|
|
58
58
|
);
|
|
59
59
|
|
|
60
60
|
export const sort_by = VmLib(
|
|
61
|
-
(data,
|
|
61
|
+
(data, key, comparator) => {
|
|
62
62
|
expectArray('data', data, null);
|
|
63
|
-
expectCallable('
|
|
63
|
+
expectCallable('key', key, data);
|
|
64
64
|
const compare = cmp(comparator, data);
|
|
65
65
|
const arr: Array<{ o: VmConst; k: VmValue }> = [];
|
|
66
66
|
const len = data.length;
|
|
@@ -68,7 +68,7 @@ export const sort_by = VmLib(
|
|
|
68
68
|
const v = data[i] ?? null;
|
|
69
69
|
arr.push({
|
|
70
70
|
o: v,
|
|
71
|
-
k: $Call(
|
|
71
|
+
k: $Call(key, [v, i, data]),
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
arr.sort((a, b) => compare(a.k, b.k));
|
|
@@ -78,12 +78,12 @@ export const sort_by = VmLib(
|
|
|
78
78
|
summary: '根据键函数对数组中的元素进行排序,并返回排序后的结果',
|
|
79
79
|
params: {
|
|
80
80
|
data: '要排序的数组',
|
|
81
|
-
|
|
81
|
+
key: '用于提取排序键的函数,接受一个元素并返回其排序键',
|
|
82
82
|
comparator: '用于比较两个排序键的函数,返回一个数字,表示它们的相对顺序,默认按升序排列',
|
|
83
83
|
},
|
|
84
84
|
paramsType: {
|
|
85
85
|
data: 'array',
|
|
86
|
-
|
|
86
|
+
key: 'fn(value: any, index: number, arr: type(data)) -> any',
|
|
87
87
|
comparator: 'fn(a: any, b: any) -> number',
|
|
88
88
|
},
|
|
89
89
|
returnsType: 'array',
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { toBoolean } from '../../../../helpers/convert/to-boolean.js';
|
|
2
|
+
import { $Call } from '../../../operations/call.js';
|
|
3
|
+
import { isSame } from '../../../operations/utils.js';
|
|
4
|
+
import type { VmAny, VmConst, VmValue } from '../../../types/index.js';
|
|
5
|
+
import { expectArray, expectCallable, VmLib } from '../../helpers.js';
|
|
6
|
+
|
|
7
|
+
/** 默认相等 */
|
|
8
|
+
function defaultEqual(a: VmValue = null, b: VmValue = null): boolean {
|
|
9
|
+
return isSame(a, b);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** 获取相等函数 */
|
|
13
|
+
function eq(equaler: VmAny, recovered: VmValue): typeof defaultEqual {
|
|
14
|
+
if (equaler == null) return defaultEqual;
|
|
15
|
+
expectCallable('equal', equaler, recovered);
|
|
16
|
+
return (a: VmValue = null, b: VmValue = null) => {
|
|
17
|
+
const ret = $Call(equaler, [a, b]);
|
|
18
|
+
return toBoolean(ret, undefined);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const unique = VmLib(
|
|
23
|
+
(data, equal) => {
|
|
24
|
+
expectArray('data', data, null);
|
|
25
|
+
const e = eq(equal, data);
|
|
26
|
+
const arr: VmConst[] = [];
|
|
27
|
+
for (const v of data) {
|
|
28
|
+
let found = false;
|
|
29
|
+
for (const u of arr) {
|
|
30
|
+
if (e(v, u)) {
|
|
31
|
+
found = true;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!found) arr.push(v ?? null);
|
|
36
|
+
}
|
|
37
|
+
return arr;
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
summary: '对数组中的元素进行去重,并返回去重后的结果',
|
|
41
|
+
params: {
|
|
42
|
+
data: '要去重的数组',
|
|
43
|
+
equal: '用于判等两个元素的函数,返回一个布尔值,默认使用严格相等比较',
|
|
44
|
+
},
|
|
45
|
+
paramsType: {
|
|
46
|
+
data: 'array',
|
|
47
|
+
equal: 'fn(a: any, b: any) -> boolean',
|
|
48
|
+
},
|
|
49
|
+
returnsType: 'array',
|
|
50
|
+
examples: ['unique([1, 2, 2, 3]) // [1, 2, 3]'],
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export const unique_by = VmLib(
|
|
55
|
+
(data, key, equal) => {
|
|
56
|
+
expectArray('data', data, null);
|
|
57
|
+
expectCallable('key', key, data);
|
|
58
|
+
const e = eq(equal, data);
|
|
59
|
+
const arr: VmConst[] = [];
|
|
60
|
+
const keys: VmValue[] = [];
|
|
61
|
+
const len = data.length;
|
|
62
|
+
for (let i = 0; i < len; i++) {
|
|
63
|
+
const v = data[i] ?? null;
|
|
64
|
+
const k = $Call(key, [v, i, data]);
|
|
65
|
+
let found = false;
|
|
66
|
+
const keysLen = keys.length;
|
|
67
|
+
for (let j = 0; j < keysLen; j++) {
|
|
68
|
+
if (e(k, keys[j])) {
|
|
69
|
+
found = true;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!found) {
|
|
74
|
+
arr.push(v);
|
|
75
|
+
keys.push(k);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return arr;
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
summary: '根据键函数对数组中的元素进行去重,并返回去重后的结果',
|
|
82
|
+
params: {
|
|
83
|
+
data: '要去重的数组',
|
|
84
|
+
key: '用于提取去重键的函数,接受一个元素并返回其去重键',
|
|
85
|
+
equal: '用于判同两个元素的函数,返回一个布尔值,默认使用严格相等比较',
|
|
86
|
+
},
|
|
87
|
+
paramsType: {
|
|
88
|
+
data: 'array',
|
|
89
|
+
key: 'fn(value: any, index: number, arr: type(data)) -> any',
|
|
90
|
+
equal: 'fn(a: any, b: any) -> boolean',
|
|
91
|
+
},
|
|
92
|
+
returnsType: 'array',
|
|
93
|
+
examples: ['unique_by(["apple", "banana", "apricot"], fn { chars(it)[0] }) // ["apple", "banana"]'],
|
|
94
|
+
},
|
|
95
|
+
);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { expectString, VmLib } from '../../helpers.js';
|
|
2
|
+
|
|
3
|
+
export const to_uppercase = VmLib(
|
|
4
|
+
(str) => {
|
|
5
|
+
return expectString('str', str).toUpperCase();
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
summary: '将字符串转换为大写',
|
|
9
|
+
params: { str: '要转换的字符串' },
|
|
10
|
+
paramsType: { str: 'string' },
|
|
11
|
+
returnsType: 'string',
|
|
12
|
+
examples: ['to_uppercase("mira") // "MIRA"'],
|
|
13
|
+
},
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const to_lowercase = VmLib(
|
|
17
|
+
(str) => {
|
|
18
|
+
return expectString('str', str).toLowerCase();
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
summary: '将字符串转换为小写',
|
|
22
|
+
params: { str: '要转换的字符串' },
|
|
23
|
+
paramsType: { str: 'string' },
|
|
24
|
+
returnsType: 'string',
|
|
25
|
+
examples: ['to_lowercase("MIRA") // "mira"'],
|
|
26
|
+
},
|
|
27
|
+
);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { expectArray, expectString, VmLib } from '../../helpers.js';
|
|
2
|
+
|
|
3
|
+
export * from './trim.js';
|
|
4
|
+
export * from './case.js';
|
|
5
|
+
export * from './search.js';
|
|
6
|
+
|
|
7
|
+
export const chars = VmLib(
|
|
8
|
+
(str) => {
|
|
9
|
+
return Array.from(expectString('str', str));
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
summary: '将字符串转换为字符数组',
|
|
13
|
+
params: { str: '要转换的字符串' },
|
|
14
|
+
paramsType: { str: 'string' },
|
|
15
|
+
returnsType: 'string[]',
|
|
16
|
+
examples: ['chars("Mira") // ["M", "i", "r", "a"]'],
|
|
17
|
+
},
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const replace = VmLib(
|
|
21
|
+
(str, search, replacement = '') => {
|
|
22
|
+
return expectString('str', str).replaceAll(
|
|
23
|
+
expectString('search', search),
|
|
24
|
+
expectString('replacement', replacement),
|
|
25
|
+
);
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
summary: '替换字符串中的指定子串',
|
|
29
|
+
params: { str: '要处理的字符串', search: '要替换的子串', replacement: '替换后的字符串' },
|
|
30
|
+
paramsType: { str: 'string', search: 'string', replacement: 'string' },
|
|
31
|
+
returnsType: 'string',
|
|
32
|
+
examples: ['replace("foo bar foo", "foo", "baz") // "baz bar baz"'],
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const split = VmLib(
|
|
37
|
+
(str, separator = '') => {
|
|
38
|
+
const s = expectString('str', str);
|
|
39
|
+
const p = expectString('separator', separator);
|
|
40
|
+
if (!p) return [...s];
|
|
41
|
+
return s.split(p);
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
summary: '将字符串拆分为子串数组',
|
|
45
|
+
params: { str: '要拆分的字符串', separator: '分隔符' },
|
|
46
|
+
paramsType: { str: 'string', separator: 'string' },
|
|
47
|
+
returnsType: 'string[]',
|
|
48
|
+
examples: ['split("a,b,c", ",") // ["a", "b", "c"]'],
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
export const join = VmLib(
|
|
53
|
+
(arr, separator = '') => {
|
|
54
|
+
expectArray('arr', arr, null);
|
|
55
|
+
const s = expectString('separator', separator);
|
|
56
|
+
return arr.map((v) => expectString(null, v)).join(s);
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
summary: '将字符串数组连接为单个字符串',
|
|
60
|
+
params: { arr: '要连接的字符串数组', separator: '分隔符' },
|
|
61
|
+
paramsType: { arr: 'string[]', separator: 'string' },
|
|
62
|
+
returnsType: 'string',
|
|
63
|
+
examples: ['join(["a", "b", "c"], "-") // "a-b-c"'],
|
|
64
|
+
},
|
|
65
|
+
);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { expectString, VmLib } from '../../helpers.js';
|
|
2
|
+
|
|
3
|
+
export const starts_with = VmLib(
|
|
4
|
+
(str, search) => {
|
|
5
|
+
return expectString('str', str).startsWith(expectString('search', search));
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
summary: '检查字符串是否以指定子串开头',
|
|
9
|
+
params: { str: '要检查的字符串', search: '要匹配的子串' },
|
|
10
|
+
paramsType: { str: 'string', search: 'string' },
|
|
11
|
+
returnsType: 'boolean',
|
|
12
|
+
examples: ['starts_with("mira", "mi") // true'],
|
|
13
|
+
},
|
|
14
|
+
);
|
|
15
|
+
export const ends_with = VmLib(
|
|
16
|
+
(str, search) => {
|
|
17
|
+
return expectString('str', str).endsWith(expectString('search', search));
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
summary: '检查字符串是否以指定子串结尾',
|
|
21
|
+
params: { str: '要检查的字符串', search: '要匹配的子串' },
|
|
22
|
+
paramsType: { str: 'string', search: 'string' },
|
|
23
|
+
returnsType: 'boolean',
|
|
24
|
+
examples: ['ends_with("mira", "ra") // true'],
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const contains = VmLib(
|
|
29
|
+
(str, search) => {
|
|
30
|
+
return expectString('str', str).includes(expectString('search', search));
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
summary: '检查字符串是否包含指定子串',
|
|
34
|
+
params: { str: '要检查的字符串', search: '要匹配的子串' },
|
|
35
|
+
paramsType: { str: 'string', search: 'string' },
|
|
36
|
+
returnsType: 'boolean',
|
|
37
|
+
examples: ['contains("hello", "ll") // true'],
|
|
38
|
+
},
|
|
39
|
+
);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { expectString, VmLib } from '../../helpers.js';
|
|
2
|
+
|
|
3
|
+
export const trim_start = VmLib(
|
|
4
|
+
(str) => {
|
|
5
|
+
return expectString('str', str).trimStart();
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
summary: '去除字符串开头的空白字符',
|
|
9
|
+
params: { str: '要处理的字符串' },
|
|
10
|
+
paramsType: { str: 'string' },
|
|
11
|
+
returnsType: 'string',
|
|
12
|
+
examples: ['trim_start(" mira") // "mira"'],
|
|
13
|
+
},
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const trim_end = VmLib(
|
|
17
|
+
(str) => {
|
|
18
|
+
return expectString('str', str).trimEnd();
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
summary: '去除字符串结尾的空白字符',
|
|
22
|
+
params: { str: '要处理的字符串' },
|
|
23
|
+
paramsType: { str: 'string' },
|
|
24
|
+
returnsType: 'string',
|
|
25
|
+
examples: ['trim_end("mira ") // "mira"'],
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const trim = VmLib(
|
|
30
|
+
(str) => {
|
|
31
|
+
return expectString('str', str).trim();
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
summary: '去除字符串两端的空白字符',
|
|
35
|
+
params: { str: '要处理的字符串' },
|
|
36
|
+
paramsType: { str: 'string' },
|
|
37
|
+
returnsType: 'string',
|
|
38
|
+
examples: ['trim(" mira ") // "mira"'],
|
|
39
|
+
},
|
|
40
|
+
);
|