Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kizahasi/flocon-script

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kizahasi/flocon-script - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

dist/fExpression.d.ts

6

dist/builtIn/Array.d.ts

@@ -1,8 +0,8 @@

import { SFunction, SValue } from '../scriptValue';
import { FFunction, FValue } from '../scriptValue';
import { Option } from '@kizahasi/option';
declare class SArrayClass extends SFunction {
declare class SArrayClass extends FFunction {
constructor();
onGetting(key: string | number): Option<SValue>;
onGetting(key: string | number): Option<FValue>;
}
export declare const arrayClass: SArrayClass;
export {};

@@ -6,3 +6,3 @@ "use strict";

const option_1 = require("@kizahasi/option");
class SArrayClass extends scriptValue_1.SFunction {
class SArrayClass extends scriptValue_1.FFunction {
constructor() {

@@ -16,5 +16,5 @@ super(() => {

case 'isArray': {
return option_1.Option.some(new scriptValue_1.SFunction(args => {
return option_1.Option.some(new scriptValue_1.FFunction(args => {
const arg = args[0];
return new scriptValue_1.SBoolean((arg === null || arg === void 0 ? void 0 : arg.type) === scriptValue_1.SType.Array);
return new scriptValue_1.FBoolean((arg === null || arg === void 0 ? void 0 : arg.type) === scriptValue_1.FType.Array);
}));

@@ -21,0 +21,0 @@ }

import * as ScriptValue from './scriptValue';
export declare class Context {
globalThis: ScriptValue.SObject;
globalThis: ScriptValue.FObject;
private varTables;
constructor(globalThis: ScriptValue.SObject);
get(name: string): ScriptValue.SValue;
assign(name: string, newValue: ScriptValue.SValue): void;
declare(name: string, value: ScriptValue.SValue, type: 'let' | 'const'): void;
constructor(globalThis: ScriptValue.FObject);
get(name: string): ScriptValue.FValue;
assign(name: string, newValue: ScriptValue.FValue): void;
declare(name: string, value: ScriptValue.FValue, type: 'let' | 'const'): void;
scopeIn(): void;
scopeOut(): void;
}

@@ -46,3 +46,3 @@ "use strict";

}
const prop = this.globalThis.get(new ScriptValue.SString(name));
const prop = this.globalThis.get(new ScriptValue.FString(name));
if (prop !== undefined) {

@@ -65,3 +65,3 @@ return prop;

}
this.globalThis.set(new ScriptValue.SString(name), newValue);
this.globalThis.set(new ScriptValue.FString(name), newValue);
}

@@ -68,0 +68,0 @@ declare(name, value, type) {

@@ -1,2 +0,3 @@

export { exec } from './exec';
export { exec, test } from './main';
export { arrayClass } from './builtIn/Array';
export { createFValue } from './scriptValue';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayClass = exports.exec = void 0;
var exec_1 = require("./exec");
Object.defineProperty(exports, "exec", { enumerable: true, get: function () { return exec_1.exec; } });
exports.createFValue = exports.arrayClass = exports.test = exports.exec = void 0;
var main_1 = require("./main");
Object.defineProperty(exports, "exec", { enumerable: true, get: function () { return main_1.exec; } });
Object.defineProperty(exports, "test", { enumerable: true, get: function () { return main_1.test; } });
var Array_1 = require("./builtIn/Array");
Object.defineProperty(exports, "arrayClass", { enumerable: true, get: function () { return Array_1.arrayClass; } });
var scriptValue_1 = require("./scriptValue");
Object.defineProperty(exports, "createFValue", { enumerable: true, get: function () { return scriptValue_1.createFValue; } });
//# sourceMappingURL=index.js.map
import { Option } from '@kizahasi/option';
declare type SObjectBase = {
get(property: SValue): SValue;
set(property: SValue, newValue: SValue): void;
declare type FObjectBase = {
get(property: FValue): FValue;
set(property: FValue, newValue: FValue): void;
toPrimitiveAsNumber(): number;

@@ -9,3 +9,3 @@ toPrimitiveAsString(): string;

};
export declare namespace SType {
export declare namespace FType {
const Boolean = "Boolean";

@@ -18,8 +18,8 @@ const Number = "Number";

}
export declare const toTypeName: (value: SValue) => "Boolean" | "Number" | "String" | "Array" | "Record" | "Function" | "null" | "undefined";
export declare class SBoolean implements SObjectBase {
export declare const toTypeName: (value: FValue) => "Boolean" | "Number" | "String" | "Array" | "Record" | "Function" | "null" | "undefined";
export declare class FBoolean implements FObjectBase {
readonly raw: boolean;
constructor(raw: boolean);
get type(): typeof SType.Boolean;
get(property: SValue): SValue;
get type(): typeof FType.Boolean;
get(property: FValue): FValue;
set(): void;

@@ -30,7 +30,7 @@ toPrimitiveAsString(): string;

}
export declare class SNumber implements SObjectBase {
export declare class FNumber implements FObjectBase {
readonly raw: number;
constructor(raw: number);
get type(): typeof SType.Number;
get(property: SValue): SValue;
get type(): typeof FType.Number;
get(property: FValue): FValue;
set(): void;

@@ -41,7 +41,7 @@ toPrimitiveAsString(): string;

}
export declare class SString implements SObjectBase {
export declare class FString implements FObjectBase {
readonly raw: string;
constructor(raw: string);
get type(): typeof SType.String;
get(property: SValue): SValue;
get type(): typeof FType.String;
get(property: FValue): FValue;
set(): void;

@@ -52,9 +52,9 @@ toPrimitiveAsString(): string;

}
export declare class SArray implements SObjectBase {
readonly raw: SValue[];
constructor(raw: SValue[]);
get type(): typeof SType.Array;
export declare class FArray implements FObjectBase {
readonly raw: FValue[];
constructor(raw: FValue[]);
get type(): typeof FType.Array;
private static isValidIndex;
get(property: SValue): SValue;
set(property: SValue, newValue: SValue): void;
get(property: FValue): FValue;
set(property: FValue, newValue: FValue): void;
toPrimitiveAsString(): string;

@@ -64,10 +64,10 @@ toPrimitiveAsNumber(): number;

}
export declare class SObject implements SObjectBase {
export declare class FObject implements FObjectBase {
private readonly raw;
constructor(base?: SObject);
get type(): typeof SType.Record;
protected onGetting(key: string | number): Option<SValue>;
get(property: SValue): SValue;
protected onSetting(key: string | number, newValue: SValue): void;
set(property: SValue, newValue: SValue): void;
constructor(base?: FObject);
get type(): typeof FType.Record;
protected onGetting(key: string | number): Option<FValue>;
get(property: FValue): FValue;
protected onSetting(key: string | number, newValue: FValue): void;
set(property: FValue, newValue: FValue): void;
toPrimitiveAsString(): string;

@@ -77,9 +77,9 @@ toPrimitiveAsNumber(): number;

}
export declare class SFunction implements SObjectBase {
export declare class FFunction implements FObjectBase {
private func;
constructor(func: (args: SValue[], isNew: boolean) => SValue);
get type(): typeof SType.Function;
exec(args: SValue[], isNew: boolean): SValue;
protected onGetting(key: string | number): Option<SValue>;
get(property: SValue): SValue;
constructor(func: (args: FValue[], isNew: boolean) => FValue);
get type(): typeof FType.Function;
exec(args: FValue[], isNew: boolean): FValue;
protected onGetting(key: string | number): Option<FValue>;
get(property: FValue): FValue;
set(): void;

@@ -90,15 +90,16 @@ toPrimitiveAsString(): string;

}
export declare type SValue = null | undefined | SBoolean | SNumber | SString | SArray | SObject | SFunction;
export declare class SGlobalRecord extends SObject {
constructor(base?: SObject);
export declare type FValue = null | undefined | FBoolean | FNumber | FString | FArray | FObject | FFunction;
export declare class FGlobalRecord extends FObject {
constructor(base?: FObject);
protected onGetting(key: string | number): import("@kizahasi/option").None | import("@kizahasi/option").Some<this>;
protected onSetting(key: string | number): void;
}
export declare function createSGlobalRecord(source: Record<string, unknown>): SGlobalRecord;
export declare const eqeqeq: (x: SValue, y: SValue) => boolean;
export declare const eqeq: (x: SValue, y: SValue) => boolean;
export declare const compareToNumber: (left: SValue, right: SValue, hint: 'default' | 'string' | 'number', comparer: (left: any, right: any) => number) => SNumber;
export declare const compareToBoolean: (left: SValue, right: SValue, hint: 'default' | 'string' | 'number', comparer: (left: any, right: any) => boolean) => SBoolean;
export declare const compareToNumberOrString: (left: SValue, right: SValue, hint: 'default', comparer: (left: any, right: any) => number | string) => SNumber | SString;
export declare const isTruthy: (value: SValue) => boolean;
export declare function createFValue(source: unknown): FValue;
export declare function createFGlobalRecord(source: Record<string, unknown>): FGlobalRecord;
export declare const eqeqeq: (x: FValue, y: FValue) => boolean;
export declare const eqeq: (x: FValue, y: FValue) => boolean;
export declare const compareToNumber: (left: FValue, right: FValue, hint: 'default' | 'string' | 'number', comparer: (left: any, right: any) => number) => FNumber;
export declare const compareToBoolean: (left: FValue, right: FValue, hint: 'default' | 'string' | 'number', comparer: (left: any, right: any) => boolean) => FBoolean;
export declare const compareToNumberOrString: (left: FValue, right: FValue, hint: 'default', comparer: (left: any, right: any) => number | string) => FNumber | FString;
export declare const isTruthy: (value: FValue) => boolean;
export {};
"use strict";
// prototype汚染を防ぐため、オブジェクトをラップしたclass(SBoolean, SNumberなど)を定義している
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTruthy = exports.compareToNumberOrString = exports.compareToBoolean = exports.compareToNumber = exports.eqeq = exports.eqeqeq = exports.createSGlobalRecord = exports.SGlobalRecord = exports.SFunction = exports.SObject = exports.SArray = exports.SString = exports.SNumber = exports.SBoolean = exports.toTypeName = exports.SType = void 0;
exports.isTruthy = exports.compareToNumberOrString = exports.compareToBoolean = exports.compareToNumber = exports.eqeq = exports.eqeqeq = exports.createFGlobalRecord = exports.createFValue = exports.FGlobalRecord = exports.FFunction = exports.FObject = exports.FArray = exports.FString = exports.FNumber = exports.FBoolean = exports.toTypeName = exports.FType = void 0;
const util_1 = require("@kizahasi/util");
const option_1 = require("@kizahasi/option");
var SType;
(function (SType) {
SType.Boolean = 'Boolean';
SType.Number = 'Number';
SType.String = 'String';
SType.Array = 'Array';
SType.Record = 'Record';
SType.Function = 'Function';
})(SType = exports.SType || (exports.SType = {}));
var FType;
(function (FType) {
FType.Boolean = 'Boolean';
FType.Number = 'Number';
FType.String = 'String';
FType.Array = 'Array';
FType.Record = 'Record';
FType.Function = 'Function';
})(FType = exports.FType || (exports.FType = {}));
const tryToPropertyName = (value) => {
switch (value === null || value === void 0 ? void 0 : value.type) {
case SType.Number:
case SType.String:
case FType.Number:
case FType.String:
return value.raw.toString();

@@ -39,3 +39,3 @@ default:

}
if ((value === null || value === void 0 ? void 0 : value.type) !== SType.Number) {
if ((value === null || value === void 0 ? void 0 : value.type) !== FType.Number) {
throw new Error(`Expected type is Number or undefined, but actually ${exports.toTypeName(value)}`);

@@ -47,4 +47,4 @@ }

switch (value === null || value === void 0 ? void 0 : value.type) {
case SType.Number:
case SType.String:
case FType.Number:
case FType.String:
break;

@@ -58,3 +58,3 @@ default:

switch (value === null || value === void 0 ? void 0 : value.type) {
case SType.Function:
case FType.Function:
return (args) => value.exec(args, false);

@@ -65,3 +65,3 @@ default:

};
class SBoolean {
class FBoolean {
constructor(raw) {

@@ -71,3 +71,3 @@ this.raw = raw;

get type() {
return SType.Boolean;
return FType.Boolean;
}

@@ -78,4 +78,4 @@ get(property) {

case 'toString':
return new SFunction(() => {
return new SString(this.raw.toString());
return new FFunction(() => {
return new FString(this.raw.toString());
});

@@ -99,4 +99,4 @@ default:

}
exports.SBoolean = SBoolean;
class SNumber {
exports.FBoolean = FBoolean;
class FNumber {
constructor(raw) {

@@ -106,3 +106,3 @@ this.raw = raw;

get type() {
return SType.Number;
return FType.Number;
}

@@ -114,5 +114,5 @@ get(property) {

case 'toString':
return new SFunction(args => {
return new FFunction(args => {
const radix = args[0];
return new SString(this.raw.toString(toNumberOrUndefined(radix)));
return new FString(this.raw.toString(toNumberOrUndefined(radix)));
});

@@ -136,4 +136,4 @@ default:

}
exports.SNumber = SNumber;
class SString {
exports.FNumber = FNumber;
class FString {
constructor(raw) {

@@ -143,3 +143,3 @@ this.raw = raw;

get type() {
return SType.String;
return FType.String;
}

@@ -151,4 +151,4 @@ get(property) {

case 'toString':
return new SFunction(() => {
return new SString(this.raw.toString());
return new FFunction(() => {
return new FString(this.raw.toString());
});

@@ -172,4 +172,4 @@ default:

}
exports.SString = SString;
class SArray {
exports.FString = FString;
class FArray {
constructor(raw) {

@@ -179,3 +179,3 @@ this.raw = raw;

get type() {
return SType.Array;
return FType.Array;
}

@@ -187,3 +187,3 @@ static isValidIndex(index) {

const index = toNumberOrString(property).toString();
if (SArray.isValidIndex(index)) {
if (FArray.isValidIndex(index)) {
return this.raw[index];

@@ -194,13 +194,6 @@ }

case 'filter':
return new SFunction(args => {
return new FFunction(args => {
const predicate = toFunction(args[0]);
const raw = this.raw.filter((value, index, array) => {
var _a;
return (_a = predicate([
value,
new SNumber(index),
new SArray(array),
])) === null || _a === void 0 ? void 0 : _a.toJObject();
});
return new SArray(raw);
const raw = this.raw.filter((value, index, array) => { var _a; return (_a = predicate([value, new FNumber(index), new FArray(array)])) === null || _a === void 0 ? void 0 : _a.toJObject(); });
return new FArray(raw);
});

@@ -212,3 +205,3 @@ }

const index = toNumberOrString(property).toString();
if (SArray.isValidIndex(index)) {
if (FArray.isValidIndex(index)) {
this.raw[index] = newValue;

@@ -230,12 +223,15 @@ return;

}
exports.SArray = SArray;
class SObject {
exports.FArray = FArray;
// Mapに変換することで、外界から受け取ったオブジェクトに対する破壊的な操作を起こせないようにしている。
class FObject {
constructor(base) {
this.raw = new Map();
if (base != null) {
this.raw = new Map(base.raw);
}
else {
this.raw = new Map();
}
}
get type() {
return SType.Record;
return FType.Record;
}

@@ -276,4 +272,4 @@ onGetting(key) {

}
exports.SObject = SObject;
class SFunction {
exports.FObject = FObject;
class FFunction {
constructor(func) {

@@ -283,3 +279,3 @@ this.func = func;

get type() {
return SType.Function;
return FType.Function;
}

@@ -321,3 +317,3 @@ exec(args, isNew) {

}
exports.SFunction = SFunction;
exports.FFunction = FFunction;
const self = 'self';

@@ -327,3 +323,3 @@ const globalThis = 'globalThis';

// baseでkeyが'self'か'globalThis'である要素は全て無視される
class SGlobalRecord extends SObject {
class FGlobalRecord extends FObject {
constructor(base) {

@@ -346,4 +342,4 @@ super(base);

}
exports.SGlobalRecord = SGlobalRecord;
function createSValue(source) {
exports.FGlobalRecord = FGlobalRecord;
function createFValue(source) {
if (source === null) {

@@ -357,31 +353,32 @@ return null;

case 'boolean':
return new SBoolean(source);
return new FBoolean(source);
case 'number':
return new SNumber(source);
return new FNumber(source);
case 'string':
return new SString(source);
return new FString(source);
case 'function':
// eslint-disable-next-line prefer-spread
return new SFunction(args => source.apply(null, args));
return new FFunction(args => source.apply(null, args));
default:
break;
}
if (source instanceof SArray ||
source instanceof SBoolean ||
source instanceof SFunction ||
source instanceof SNumber ||
source instanceof SObject ||
source instanceof SString) {
if (source instanceof FArray ||
source instanceof FBoolean ||
source instanceof FFunction ||
source instanceof FNumber ||
source instanceof FObject ||
source instanceof FString) {
return source;
}
if (Array.isArray(source)) {
return new SArray(source.map(x => createSValue(x)));
return new FArray(source.map(x => createFValue(x)));
}
return createSRecord(source);
return createFObject(source);
}
exports.createFValue = createFValue;
// __proto__ のチェックなどは行われない
function createSRecord(source) {
const result = new SObject();
function createFObject(source) {
const result = new FObject();
for (const key in source) {
result.set(new SString(key), createSValue(source[key]));
result.set(new FString(key), createFValue(source[key]));
}

@@ -391,6 +388,6 @@ return result;

// keyが'self'か'globalThis'である要素は無視されることに注意
function createSGlobalRecord(source) {
return new SGlobalRecord(createSRecord(source));
function createFGlobalRecord(source) {
return new FGlobalRecord(createFObject(source));
}
exports.createSGlobalRecord = createSGlobalRecord;
exports.createFGlobalRecord = createFGlobalRecord;
// https://ja.javascript.info/object-toprimitive

@@ -421,5 +418,5 @@ const toPrimitive = (value, hint) => {

switch (x.type) {
case SType.Boolean:
case SType.Number:
case SType.String:
case FType.Boolean:
case FType.Number:
case FType.String:
if ((y === null || y === void 0 ? void 0 : y.type) !== x.type) {

@@ -444,9 +441,9 @@ return false;

switch (x.type) {
case SType.Boolean:
case SType.Number:
case SType.String:
case FType.Boolean:
case FType.Number:
case FType.String:
switch (y.type) {
case SType.Boolean:
case SType.Number:
case SType.String:
case FType.Boolean:
case FType.Number:
case FType.String:
// eslint-disable-next-line eqeqeq

@@ -460,5 +457,5 @@ return x.raw == y.raw;

switch (y.type) {
case SType.Boolean:
case SType.Number:
case SType.String:
case FType.Boolean:
case FType.Number:
case FType.String:
// eslint-disable-next-line eqeqeq

@@ -476,7 +473,7 @@ return toPrimitive(x, 'default') == y.raw;

const compareToNumber = (left, right, hint, comparer) => {
return new SNumber(compare(left, right, hint, comparer));
return new FNumber(compare(left, right, hint, comparer));
};
exports.compareToNumber = compareToNumber;
const compareToBoolean = (left, right, hint, comparer) => {
return new SBoolean(compare(left, right, hint, comparer));
return new FBoolean(compare(left, right, hint, comparer));
};

@@ -487,5 +484,5 @@ exports.compareToBoolean = compareToBoolean;

if (typeof r === 'number') {
return new SNumber(r);
return new FNumber(r);
}
return new SString(r);
return new FString(r);
};

@@ -499,5 +496,5 @@ exports.compareToNumberOrString = compareToNumberOrString;

switch (value.type) {
case SType.Boolean:
case SType.Number:
case SType.String:
case FType.Boolean:
case FType.Number:
case FType.String:
if (value.raw) {

@@ -504,0 +501,0 @@ return true;

{
"version": "0.1.0",
"version": "0.2.0",
"license": "MIT",

@@ -20,3 +20,3 @@ "main": "dist/index.js",

"prettier": {
"printWidth": 80,
"printWidth": 100,
"semi": true,

@@ -31,2 +31,6 @@ "singleQuote": true,

"author": "kizahasi",
"repository": {
"type": "git",
"url": "https://github.com/kizahasi/flocon-script"
},
"devDependencies": {

@@ -33,0 +37,0 @@ "@types/estree": "^0.0.49",

@@ -1,3 +0,3 @@

# @kizahasi/sandbox
# @kizahasi/flocon-script
Executes javascript safely, but some features are not implemented.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc