npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lv00/toolkit

v1.2.10

Published

[![Publish to NPM](https://github.com/Benoit-Welsch/ToolKitJs/actions/workflows/publish.yml/badge.svg)](https://github.com/Benoit-Welsch/ToolKitJs/actions/workflows/publish.yml) [![Unit Test](https://github.com/Benoit-Welsch/ToolKitJs/actions/workflows/te

Downloads

418

Readme

🛠️ ToolKit

Publish to NPM Unit Test npm version License: MIT

Versatile JavaScript Toolkit for Everyday Use

Table of Contents

Installation

npm install @lv00/toolkit # or
pnpm install @lv00/toolkit # or
yarn add @lv00/toolkit # or
bun install @lv00/toolkit

Usage

import { ... } from "@lv00/toolkit";

Check

Easily check data type and format.

import { Is } from "@lv00/toolkit";

is.ip('127.0.0.1'); // true
is.ip('1.1.1'); // false

is.email('[email protected]'); // true
is.email('test@test'); // false

... // use intellisense to see more

CSV

Create CSV on the fly.

import { CSV } from '@lv00/toolkit';

const csv = new CSV({ header: ['name', 'age'] });

// Add a line to the CSV
csv.addLine(['John', 20]);

// Add value one by one
csv.addSequentially('Jane & Doe');
csv.addSequentially(21);
csv.addSequentially('Jack');
csv.addSequentially(22);

// Get the CSV as string
csv.toString('|');

// Clear the CSV and keep the header
csv.clear();

// Convert the CSV to a JS object
csv.toObject();
// [
//   { name: 'John', age: 20 },
//   { name: 'Jane & Doe', age: 21 },
//   { name: 'Jack', age: 22 }
// ]

// Read CSV from string
const csv2 = CSV.readString('name,age\r\nJohn,20\r\nJane,21\r\nJack,22', ',');
csv2.toString('|');

Gen

Generate pseudo-random data

random Name

import { Gen } from '@lv00/toolkit';

const newName = Gen.randomName(); // antonelli-xenodochial

random Number

import { Gen } from '@lv00/toolkit';

const newNumber = Gen.randomNumber(0, 100); // 42

Log

Easily log to various outputs.

import { Log } from 'lv00/toolkit';

const { Logger, Console, Level, File, Csv, Json } = Log;

// Define the endpoint of the log (transporter)
const logger = new Logger({
  t: [
    new Console(), // Log all levels to the console
    new File({ l: [Level.INFO], path: 'log.txt' }), // Log only INFO to a text based file
    new Csv({ l: [Level.ERROR], path: 'log.csv' }), // Log only ERROR to a CSV file
    new Json({ l: [Level.DEBUG], path: 'log.json' }), // Log only DEBUG to a JSON file
  ],
});

logger.log('Hello, World!'); // log to all transports registered for the level INFO
logger.log('Hello, World!', Level.ERROR); // log to all transports registered for the level ERROR

logger.info('Hello, World!');
logger.ok('Hello, World!');
logger.warn('Hello, World!');
logger.error('Hello, World!');
logger.debug('Hello, World!');

// Log an error
new Promise((_, reject) => {
  reject(new Error('Promise Error'));
}).catch((e) => logger.catch(e));

Parser

Parse data to object.

Dot

import { Parser } from "@lv00/toolkit";

const data = `battery.charge: 100
battery.charge.low: 20
battery.runtime: 995
battery.type: PbAc
device.mfr: EATON
device.model: Ellipse PRO 650
device.serial: P354M05BE0
device.type: ups
driver.name: usbhid-ups`;

const result = dot(data);
console.log(result);
// Will return the following object
{
  battery: {
    charge: {
      _value: "100",
      low: "20",
    },
    runtime: "995",
    type: "PbAc",
  },
  device: {
    mfr: "EATON",
    model: "Ellipse PRO 650",
    serial: "P354M05BE0",
    type: "ups",
  },
  driver: {
    name: "usbhid-ups",
  },
}

Plugin

Lazy loading of plugins.

import { Plugin } from "@lv00/toolkit";

// defined a plugin to exptend from (src/Plugin/index.ts)
export default class ExamplePlugin extends Plugin {
  name: string;
  constructor(name: string) {
    super();
    this.name = name;
  }
  execute() {
    return `Plugin ${this.name} executed`;
  }
}

// Create all the plugins you need

// Plugin 1 (src/Plugin/ExamplePlugin1.ts)
export default class ExamplePlugin1 extends ExamplePlugin {
  constructor() {
    super("1");
  }
}

// Plugin 2 (src/Plugin/ExamplePlugin2.ts)
export default class ExamplePlugin2 extends ExamplePlugin {
  constructor() {
    super("2");
  }
}

// Import the plugins 
Plugin.import("./src/Plugin/")
.forEach((plugin) => {
  const p = new plugin();
  p.execute();
});
// or
// Load all the plugins
Plugin.load("./src/Plugin/")
.forEach((plugin) => {
  plugin.execute();
});

Scanner

Read folder synchronously without headache

import { Scanner } from '@lv00/toolkit';

const scanner = Scanner.readFolder('./path/to/folder');

// Available properties
scanner.parent;
scanner.files;
scanner.folders;
scanner.path;

// return a array of files
scanner.flat();
// return json and remove circular references
scanner.toJson();

Unit

Convert data to human readable format

import { Unit } from './src';

// By default it will use 1000 as base
// and K, M, G, T, P as units
const size = Unit.sizeToUnitAuto(1000);

size.n; // 1
size.unit; // K
size.toString(); // 1K
size.round(2); // 1.00
size.roundToString(2); // 1.00K

Url

Conveniently build urls with query parameters.

import { Url, Uri } from '@lv00/toolkit';

const url = 'https://lv0.eu/';
const query = {
  p: '2',
  brand: ['sony', 'microsoft', 'nintendo'],
};

const q = Url.buildUrlWithQuery(url, query);
console.log(q.toString()); // https://lv0.eu/?p=2&brand=sony&brand=microsoft&brand=nintendo'

const uri = new Uri(
  url,
  "GET"
  query,
  )
const json = await uri.fetchJson()