functions_julman_api
Advanced tools
Comparing version 1.0.4 to 1.1.0
{ | ||
"name": "functions_julman_api", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "A API for store functions to execute later.", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -0,1 +1,3 @@ | ||
const { list } = require(".."); | ||
module.exports = class Functions { | ||
@@ -14,2 +16,7 @@ constructor () { | ||
static add(name, callback) { | ||
if (list.has(name)) throw new TypeError("The name is alrady used"); | ||
list.set(name, callback); | ||
} | ||
remove(name) { | ||
@@ -22,2 +29,9 @@ if (!this.list.has(name)) throw new TypeError("404: Not Found"); | ||
static remove(name) { | ||
if (!list.has(name)) throw new TypeError("404: Not Found"); | ||
var rv = list.get(name); | ||
list.delete(name); | ||
return rv; | ||
} | ||
execute(name) { | ||
@@ -28,2 +42,7 @@ if (!this.list.has(name)) throw new TypeError("404: Not Found"); | ||
static execute(name) { | ||
if (!list.has(name)) throw new TypeError("404: Not Found"); | ||
list.get(name).call(this, name); | ||
} | ||
replace(name, new_callback) { | ||
@@ -37,2 +56,11 @@ if (!this.list.has(name)) throw new TypeError("404: Not Found"); | ||
static replace(name, new_callback) { | ||
if (!list.has(name)) throw new TypeError("404: Not Found"); | ||
var rv = list.get(name); | ||
list.delete(name); | ||
if (list.has(name)) throw new TypeError("The name is alrady used"); | ||
list.set(name, callback); | ||
return rv; | ||
} | ||
clear() { | ||
@@ -42,2 +70,6 @@ this.list.clear(); | ||
static clear() { | ||
list.clear(); | ||
} | ||
static instance() { | ||
@@ -44,0 +76,0 @@ return new Functions(); |
module.exports = { | ||
Functions: require("./functions/index.js") | ||
}; | ||
Functions: require("./functions/index.js"), | ||
}; | ||
exports.list = new Map(); |
@@ -25,2 +25,12 @@ import { add, instance } from "../src"; | ||
public add(name: String, callback: function(String): void): void; | ||
/** | ||
* Add function | ||
* @param name The name for the function ***(arg0 = String -> the function name)*** | ||
* @param callback The code to execute when function called | ||
* @author JulMan (MinecraftJulMan) ---> https://github.com/MinecraftJulMan | ||
* @throws Can throw a "*TypeError*" if the name is alrady use | ||
* @license ISE -> https://github.com/MinecraftJulMan/functions_julman_api/blob/master/LICENCE | ||
* @description See on [GitHub](https://github.com/MinecraftJulMan/functions_julman_api/wiki/Functions#addname-callback-go-to-source) | ||
*/ | ||
public static add(name: String, callback: function(String): void): void; | ||
@@ -37,2 +47,12 @@ /** | ||
public remove(name: String): function(String): void; | ||
/** | ||
* Remove a function | ||
* @param name The function's name to remove | ||
* @returns {function(String): void} The function removed | ||
* @author JulMan (MinecraftJulMan) ---> https://github.com/MinecraftJulMan | ||
* @throws Can throw "*TypeError*" if the function not exist | ||
* @license ISE -> https://github.com/MinecraftJulMan/functions_julman_api/blob/master/LICENCE | ||
* @description See on [GitHub](https://github.com/MinecraftJulMan/functions_julman_api/wiki/Functions#removename-go-to-source) | ||
*/ | ||
public static remove(name: String): function(String): void; | ||
@@ -48,2 +68,11 @@ /** | ||
public execute(name: String): void; | ||
/** | ||
* Execute a function | ||
* @param name The function's name to execute | ||
* @author JulMan (MinecraftJulMan) ---> https://github.com/MinecraftJulMan | ||
* @throws Can throw "*TypeError*" if the function not exist | ||
* @license ISE -> https://github.com/MinecraftJulMan/functions_julman_api/blob/master/LICENCE | ||
* @description See on [GitHub](https://github.com/MinecraftJulMan/functions_julman_api/wiki/Functions#executename-go-to-source) | ||
*/ | ||
public static execute(name: String): void; | ||
@@ -57,2 +86,9 @@ /** | ||
public clear(): void; | ||
/** | ||
* Clear functions' list | ||
* @author JulMan (MinecraftJulMan) --> https://github.com/MinecraftJulMan | ||
* @license ISE -> https://github.com/MinecraftJulMan/functions_julman_api/blob/master/LICENCE | ||
* @description See on [GitHub](https://github.com/MinecraftJulMan/functions_julman_api/wiki/Functions#clear-go-to-source) | ||
*/ | ||
public static clear(): void; | ||
@@ -80,3 +116,15 @@ /** | ||
public replace(name: String, new_callback: function(String): void): function(String): void; | ||
/** | ||
* Change function's executor | ||
* @param name The function name to edit | ||
* @param new_callback The new function's code | ||
* @returns The old function's code | ||
* @author JulMan (MinecraftJulMan) ---> https://github.com/MinecraftJulMan | ||
* @throws Can throw a "*TypeError*" if the name is alrady use | ||
* @license ISE -> https://github.com/MinecraftJulMan/functions_julman_api/blob/master/LICENCE | ||
* @description See on [GitHub](https://github.com/MinecraftJulMan/functions_julman_api/wiki/Functions#replacename-callback-go-to-source) | ||
*/ | ||
public static replace(name: String, new_callback: function(String): void): function(String): void; | ||
} | ||
} |
11788
178