Added original helpers from eluna-ts

This commit is contained in:
Ben Carter
2023-09-10 03:03:14 -04:00
parent f237b59ce4
commit 01cc3da42d
11 changed files with 97 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import { stringSanitizer } from "../db.helpers";
declare var global: any;
global.string = {};
global.string.gsub = function (
str: string,
pattern: string,
fn: any,
): [string, number] {
const regExp = RegExp(pattern, "g");
return [
str.replace(regExp, fn),
0,
];
};
describe("Test db.helpers.ts", () => {
it("Test string to sanitize", () => {
const toSanitize = "'\"\\ \\%\tt\be\0s',\"\x1at\n\r\"'";
const res = stringSanitizer(toSanitize);
expect(res).not.toEqual(toSanitize);
});
it("Test normal string", () => {
const toSanitize = "tonotnormalize";
const res = stringSanitizer(toSanitize);
expect(res).toEqual(toSanitize);
});
});

View File

@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"lib": [
"DOM","ESNext"
],
},
"exclude": []
}

7
common/src/db.helpers.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
/**
* Sanitize a string for SQL
*
* @param str
* @returns Sanitized string
*/
export declare function stringSanitizer(str: string): string;

13
common/src/db.helpers.ts Normal file
View File

@@ -0,0 +1,13 @@
/**
* Sanitize a string for SQL
*
* @param str
* @returns Sanitized string
*/
export function stringSanitizer(str: string): string {
return string.gsub(
str,
"[';\\, ]",
"",
)[0];
}

View File

@@ -0,0 +1,7 @@
/**
* Sanitize a string for SQL
*
* @param str
* @returns Sanitized string
*/
export declare function stringSanitizer(str: string): string;

View File

@@ -0,0 +1,6 @@
export type IRegisterHook<T> = (hook: T,
/** the number of times the function will be called, 0 means "always call this function" */
shots?: number) => any;
export type IRegisterHookWithId<T> = (id: number, hook: T,
/** the number of times the function will be called, 0 means "always call this function" */
shots?: number) => any;

2
common/src/declarations/index.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
export * from "./hook.helpers";
export * from "./db.helpers";

6
common/src/hook.helpers.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
export declare type IRegisterHook<T> = (hook: T,
/** the number of times the function will be called, 0 means "always call this function" */
shots?: number) => any;
export declare type IRegisterHookWithId<T> = (id: number, hook: T,
/** the number of times the function will be called, 0 means "always call this function" */
shots?: number) => any;

View File

@@ -0,0 +1,12 @@
export type IRegisterHook<T> = (
hook: T,
/** the number of times the function will be called, 0 means "always call this function" */
shots?: number
) => any;
export type IRegisterHookWithId<T> = (
id: number,
hook: T,
/** the number of times the function will be called, 0 means "always call this function" */
shots?: number,
) => any;

2
common/src/index.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
export * from "./hook.helpers";
export * from "./db.helpers";

2
common/src/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export * from "./hook.helpers"
export * from "./db.helpers"