naughty-util
v0.8.0
Published
Util functions for node.js
Downloads
112
Readme
Naughty Util
Usage
- Install:
npm install naughty-util - Require:
const utils = require("naughty-util");
Examples
Promisify
const fs = require("node:fs");
const { async } = require("naughty-util");
const readFile = async.promisify(fs.readFile);
const string = await readFile(__filename, "utf-8");
const buffer = await readFile(__filename);Factorify
const { abstract } = require("naughty-util");
const mapping = {
discord: async () => {
const res = await fetch(url, options);
return res.image;
},
twitter: async () => {
const res = await fetch(url, options);
return res.profile.image.url;
},
twitch: async () => {
const res = await fetch(url, options);
return res.user_profile.icon;
},
};
const DEFAULT_IMAGE = '...';
const strategies = abstract.factorify(mapping, async () => DEFAULT_IMAGE);
const img1 = await strategies("discord")();
const img2 = await strategies("linkedin")(); // default imageEnumerate
const { iterator } = require("naughty-util");
const dataset = ["a", "b", "c", "d"];
for(const entry of iterator.enumerate(dataset)){
entry[0] // value: "a"
entry[1] // index: 0
}