0.5.5 • Published 2 years ago
inadequado v0.5.5
For the most part this package is for personal use, but you can use it too :)
Currently implemented: LocalStorage KeyTracking Prototypes Tools
Already done, but no instructions.
namespace LocalStorage
Allows you to use LocalStorage conveniently.
Examples
LocalStorage.setItem("key", 1);
LocalStorage.getItem("key"); // 1 (number)
LocalStorage.setItem("key", "1");
LocalStorage.getItem("key"); // "1" (string)
LocalStorage.setItem("key", { a: "A" });
LocalStorage.getItem("key"); // { a: "A" } (object)
class A {}
LocalStorage.setItem("key", { a: new A() });
LocalStorage.getItem("key"); // { a: {} } (object)
In the case of
class A {}
, the information that it is an instance of classA
will be lost when the object is received.
Types
type localStorageTypes = number | string | (number | string[]) | object;
export function getItem<T extends localStorageTypes>(key: string): T | null;
export function setItem(key: string, value: localStorageTypes): void;
namespace KeyTracking
Helps you keep track of keystrokes and perform functions when certain combinations are pressed.
Examples
KeyTracking.createCombination("KeyH", () => console.log("Hello"));
KeyTracking.createCombination(["ControlLeft", "KeyS"], () => console.log("Save"));
KeyTracking.deleteCombination(["ControlLeft", "KeyS"]);
It is not recommended to create combinations of more than 3 keys.
namespace Prototypes
Expansion for primitive types
How to use
import { Prototypes } from "inadequado/dist/Tools";
Prototypes.Array();
Prototypes.String();
// ... OR ...
Prototypes.All();
List of new methods for String
:
/** Removes HTML tags from the string */
stripTags(): this;
/** Converts special characters into HTML entities */
htmlspecialchars(remquotes?: boolean): this;
List of new methods for Array
:
/** Shuffle the array */
shuffle(): T[];
/** Get random elements from an array.
* @module Inadequado
*/
randomElements(count: number, prohibitRepetition?: boolean): T[];
randomElements(count?: 1): T;
Tools
Contains small and useful functionality
random(100, true) // 100%, be true
random(50, true) // 50%, be true | null,
random(0, true) // 0%, be null
randomRange(100, 500) // number from 100 to 500