You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@splitscript.js/core

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@splitscript.js/core - npm Package Compare versions

Comparing version

to
2.3.0

4

CHANGELOG.md

@@ -0,1 +1,5 @@

# 2.3.0
Add handleError function
# 2.2.2

@@ -2,0 +6,0 @@

22

dist/node/cjs/events/index.js

@@ -41,2 +41,3 @@ "use strict";

var import__ = require("../index.js");
var import_variable = __toESM(require("../utils/variable.js"));
const registered = [];

@@ -66,7 +67,3 @@ class EventEmitter {

import(url.toString()).then((module2) => {
if (typeof module2.default === "function") {
module2.default(data);
} else if (typeof module2 === "function") {
module2(data);
} else {
if (typeof module2.default !== "function" && typeof module2 !== "function")
return console.log(

@@ -78,2 +75,15 @@ import_ansi_colors.default.bgRed(" ERROR "),

);
try {
if (typeof module2.default === "function") {
module2.default(data);
} else if (typeof module2 === "function") {
module2(data);
}
} catch (e) {
const handleFunctions = import_variable.default.get("handleFunctions");
if (!handleFunctions || handleFunctions?.length === 0)
throw e;
for (const func of handleFunctions) {
func(data, e);
}
}

@@ -140,3 +150,3 @@ });

);
}).catch((err) => {
}).catch(() => {
let current = {

@@ -143,0 +153,0 @@ packages: {

@@ -32,2 +32,3 @@ "use strict";

EventEmitter: () => import_events.EventEmitter,
handleError: () => handleError,
root: () => root

@@ -53,6 +54,12 @@ });

}
function handleError(handleFunction) {
const handleFunctions = import_variable.default.get("handleFunctions") ?? [];
handleFunctions?.push(handleFunction);
import_variable.default.set("handleFunctions", handleFunctions);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
EventEmitter,
handleError,
root
});

@@ -8,2 +8,3 @@ import fs from "fs";

import { root } from "../index.js";
import variable from "../utils/variable.js";
const registered = [];

@@ -33,7 +34,3 @@ class EventEmitter {

import(url.toString()).then((module) => {
if (typeof module.default === "function") {
module.default(data);
} else if (typeof module === "function") {
module(data);
} else {
if (typeof module.default !== "function" && typeof module !== "function")
return console.log(

@@ -45,2 +42,15 @@ ansiColors.bgRed(" ERROR "),

);
try {
if (typeof module.default === "function") {
module.default(data);
} else if (typeof module === "function") {
module(data);
}
} catch (e) {
const handleFunctions = variable.get("handleFunctions");
if (!handleFunctions || handleFunctions?.length === 0)
throw e;
for (const func of handleFunctions) {
func(data, e);
}
}

@@ -107,3 +117,3 @@ });

);
}).catch((err) => {
}).catch(() => {
let current = {

@@ -110,0 +120,0 @@ packages: {

@@ -17,6 +17,12 @@ import path from "path";

}
function handleError(handleFunction) {
const handleFunctions = variable.get("handleFunctions") ?? [];
handleFunctions?.push(handleFunction);
variable.set("handleFunctions", handleFunctions);
}
import { EventEmitter } from "./events/index.js";
export {
EventEmitter,
handleError,
root
};
declare function root(dir?: string): string;
type HandleFunction = (data: object, error: unknown) => unknown;
declare function handleError(handleFunction: HandleFunction): void;
export { EventEmitter } from './events/index.js';
export { root };
export { root, handleError };
export type { HandleFunction };
/// <reference types="node" />
import EventEmitter from 'node:events';
import { HandleFunction } from '../';
export declare const variable: {
[key: string]: string | undefined;
root?: string;
handleFunctions?: HandleFunction[];
};
export declare const emitter: EventEmitter;
export declare function set(key: string, value: string): void;
export declare function get(key: string): string | undefined;
export declare function set<Key extends keyof typeof variable>(key: Key, value: (typeof variable)[Key]): void;
export declare function get<Key extends keyof typeof variable>(key: Key): (typeof variable)[Key];
declare const _default: {
variable: {
[key: string]: string | undefined;
root?: string | undefined;
handleFunctions?: HandleFunction[] | undefined;
};

@@ -13,0 +16,0 @@ emitter: EventEmitter;

{
"name": "@splitscript.js/core",
"version": "2.2.2",
"version": "2.3.0",
"description": "Core SplitScript.js library",

@@ -5,0 +5,0 @@ "types": "./dist/types/index.d.ts",

@@ -50,2 +50,19 @@ <a href="#">

## Catching Errors
You can use the `handleError` for catching all listeners that fail
```ts
import { handleError } from '@splitscript.js/core'
handleError((data, err) => {
console.log('Error: ', err)
})
// You can add multiple error handlers
handleError((data, err) => {
console.log('This also handles the same error: ', err)
})
```
⚠ Make sure you put `handleError()` before any other code so it can handle all errors
## Other packages

@@ -57,4 +74,4 @@

<sub><code>v2.2.2</code> | by [ultraviolet](https://github.com/ultravioletasdf)</sub>
<sub><code>v2.3.0</code> | by [ultraviolet](https://github.com/ultravioletasdf)</sub>
</div>