mirror of
https://github.com/araxiaonline/wow-eluna-ts-module.git
synced 2026-06-13 02:42:22 -04:00
Added original helpers from eluna-ts
This commit is contained in:
31
common/src/__tests__/db.helpers.spec.ts
Normal file
31
common/src/__tests__/db.helpers.spec.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
9
common/src/__tests__/tsconfig.json
Normal file
9
common/src/__tests__/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
"DOM","ESNext"
|
||||
],
|
||||
},
|
||||
"exclude": []
|
||||
}
|
||||
7
common/src/db.helpers.d.ts
vendored
Normal file
7
common/src/db.helpers.d.ts
vendored
Normal 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
13
common/src/db.helpers.ts
Normal 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];
|
||||
}
|
||||
7
common/src/declarations/db.helpers.d.ts
vendored
Normal file
7
common/src/declarations/db.helpers.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Sanitize a string for SQL
|
||||
*
|
||||
* @param str
|
||||
* @returns Sanitized string
|
||||
*/
|
||||
export declare function stringSanitizer(str: string): string;
|
||||
6
common/src/declarations/hook.helpers.d.ts
vendored
Normal file
6
common/src/declarations/hook.helpers.d.ts
vendored
Normal 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
2
common/src/declarations/index.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./hook.helpers";
|
||||
export * from "./db.helpers";
|
||||
6
common/src/hook.helpers.d.ts
vendored
Normal file
6
common/src/hook.helpers.d.ts
vendored
Normal 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;
|
||||
12
common/src/hook.helpers.ts
Normal file
12
common/src/hook.helpers.ts
Normal 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
2
common/src/index.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./hook.helpers";
|
||||
export * from "./db.helpers";
|
||||
2
common/src/index.ts
Normal file
2
common/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./hook.helpers"
|
||||
export * from "./db.helpers"
|
||||
Reference in New Issue
Block a user