@lucania/toolbox
v1.0.21
Published
A utility library delivering many quality of life improvements to both browser and node environments.
Downloads
132
Maintainers
Readme
A JavaScript/TypeScript Toolbox
A utility library delivering many quality of life improvements to both browser and node environments.
This project has 3 sections.
- Shared - @lucania/toolbox/shared - Contains general features purely for manipulating data and works irrespective of environment, I.E. runs in both the client and server.
- Server - @lucania/toolbox/server - Contains features to aid in server-side development and requires a node environment to run. Do not import this library in your client-side codebase.
- Client - @lucania/toolbox/client - Contains features to aid in client-side development and requires a browser environment to run. Do not import this library in your server-side codebase.
Getting started
Install the package
This project uses NPM, thus can be installed with...
npm install --save @lucania/toolbox
Use the libraries
Example usage of the "Shared" library.
// "Shared" currently exports 3 namespaces
import { Data, Error, Text } from "@lucania/toolbox/shared";
// Example usage of functions from the "Data" namespace.
const weatherReport = {
weather: {
type: "sunny",
temperature: 21
}
}
const weatherType = Data.get(weatherReport, "weather.type", "unknown");
Data.assert(weatherType === "sunny", "The weather is too bad to go shopping!");
// Example usage of functions from the "Error" namespace.
throw new Error.Fatal("Something unrecoverably bad happened!");
// Example usage of functions from the "Text" namespace.
const women = ["Catherine", "Kathryn"];
const distance = Text.getLevenshteinDistance(women[0], women[1]);
const message = `${Text.toPrettyList(women)} have names that sound the same, but differ by ${distance} characters in spelling!`;
// See inline documentation for more usage details and to see what is available.
Example usage of the "Server" library.
import { ConsoleColor, File } from "@lucania/toolbox/server";
// Example usage of functions from the "ConsoleColor" namespace.
const { red, green, blue, reset } = ConsoleColor.Common;
console.log(`Unpopular opinion, I prefer my computer without ${red}R${green}G${blue}B${reset}.`);
// Example usage of functions from the "File" namespace.
let fiona = await File.read("C:/Fiona Dossier.txt", "utf8");
fiona = fiona.replaceAll("life", "death");
await File.write("C:/Fiona Dossier.txt", fiona, "utf8");
/** {@link https://pastebin.com/E8af0zei Fiona Dossier} */
Example usage of the "Client" library.
import { Network, Dom, Cookies } from "@lucania/toolbox/client";
// I got tired, so gave up on this section. I'll get to it... eventually.
// Just look at the source...
| :warning: | This project uses subpath exports only supported in Node v12.7.0+. Ensure you use one of Node's new module resolution strategies, I.E. NodeNext. | |-|:-|