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

bucky.js

v1.2.1

Published

Simple npm that has several functions to use in everyday development.

Downloads

103

Readme


Table of contents

Installation

Your Node.js must be version 16.6.0 or higher!

# Using npm:
npm install bucky.js --save

# Using yarn:
yarn add bucky.js

Functions

Generators

GenerateDecimal

A function that will generate random decimals.

If you want to inspect the code, click here.

import { generateDecimal } from 'bucky.js';

console.log(generateDecimal()); // It will generate a randomized decimal.

GenerateHex

A function that generates random hexadecimal.

If you want to inspect the code, click here.

import { generateHex } from 'bucky.js';

console.log(generateHex()); // Will generate a randomized hex.

GeneratePassword

This function will generate a password with the number of characters you define in the parameters.

If you want to inspect the code, click here.

import { generatePassword } from 'bucky.js';

let password = generatePassword(15); // 15 characters
console.log(password);

GenerateRGB

Use this function to create a random RGB.

If you want to inspect the code, click here.

import { generateRGB } from 'bucky.js';

let myRGB = generateRGB(); // Will generate the random RGB.
console.log(myRGB); // It will return an Array with the RGB values.

Verifications

IsDirectory

Use to check if a directory exists.

If you want to inspect the code, click here.

import { isDirectory } from 'bucky.js';
import path from 'node:path';

let directory = path.resolve('path', 'to', 'directory');
console.log(isDirectory(directory)); // Returns a Boolean value.

IsEmail

Use this function to verify valid emails.

If you want to inspect the code, click here.

import { isEmail } from 'bucky.js';

let myEmail = '[email protected]';
console.log(isEmail(myEmail)); // Returns a Boolean value.

IsEmptyDirectory

Use this function to check if a directory is empty.

If you want to inspect the code, click here.

import { isEmptyDirectory } from 'bucky.js';
import path from 'node:path';

let directory = path.resolve('path', 'to', 'directory');
console.log(isEmptyDirectory(directory)); // Returns a Boolean value.

IsEmptyFile

Use this function to check if a file is empty.

If you want to inspect the code, click here.

import { isEmptyFile } from 'bucky.js';
import path from 'node:path';

let file = path.resolve('path', 'to', 'file');
console.log(isEmptyFile(file)); // Returns a Boolean value.

IsFile

Use this function to check whether it is a file or not.

If you want to inspect the code, click here.

import { isFile } from 'bucky.js';
import path from 'node:path';

let file = path.resolve('path', 'to', 'file');
console.log(isEmptyFile(file)); // Returns a Boolean value.

IsHex

Use this function to check whether a hex or not.

If you want to inspect the code, click here.

import { isHex } from 'bucky.js';

console.log(isHex('#FFA500')); // Returns a Boolean value.

IsURL

Use this function to check if it's a URL.

If you want to inspect the code, click here.

import { isURL } from 'bucky.js';

let url = 'https://www.npmjs.com/package/bucky.js';
console.log(isURL(url));  // Returns a Boolean value.

Other functions

CapitalizeFirstLetter

Use this function to capitalize the first letter of a string.

If you want to inspect the code, click here.

import { capitalizefirstletter } from 'bucky.js';

let myText = 'your text to capitalize.';
console.log(capitalizefirstletter(myText)); // ouptut: Your text to capitalize.

CompareStrings

Use this function to see how much one key resembles another.

If you want to inspect the code, click here.

import { compareStrings } from 'bucky.js';

let result = compareStrings('buc', 'bucky');
console.log(result); // ouptut: 0.7745966692414834

DaysAgo

Use this function to check when days ago has a date.

If you want to inspect the code, click here.

import { daysAgo } from 'bucky.js';

let date = new Date();
  date.setYear(date.getFullYear() - 18); // 2004-06-13T00:50:22.624Z
console.log(daysAgo(date)); // output: 6574

FindArrayDuplicates

Use this function to remove duplicate items from an Array.

If you want to inspect the code, click here.

import { findArrayDuplicates } from 'bucky.js';

let list = ['bucky', 'silva', 'john', 'bucky'];
console.log(findArrayDuplicates(list)); // output: ['bucky'];

FormatSizeUnits

Use this function to format the byte size.

If you want to inspect the code, click here.

import { formatSizeUnits } from 'bucky.js';

let memoryUsage = process.memoryUsage.rss();
console.log(formatSizeUnits(memoryUsage)); // ouput: 31.60 MB

Ms

Use this function to format milliseconds.

If you want to inspect the code, click here.

import { ms } from 'bucky.js';

console.log(ms(12e5)); // output: {
//  year: 0,
//  month: 0,
//  day: 0,
//  hour: 0,
//  minute: 20,
//  second: 0,
//  milliSecond: 0,
//  microSecond: 0,
//  nanoSecond: 0,
//  abbreviated: '20m'
//}

console.log(ms(12e5, 'en-us')); // output: 20 minutes

Pagination

Used to navigate between values in an Array more easily.

If you want to inspect the code, click here.

import { Pagination } from 'bucky.js';

let pagination = new Pagination([
  { foo: 'bar', type: 1 },
  { bar: 'foo', type: 2 }
]);

console.log(pagination); // output: Pagination {...}
console.log(pagination.current); // ouput: { foo: 'bar', type: 1 }
console.log(pagination.next()); // output: { foo: 'bar', type: 2 }
console.log(pagination.back()); // ouput: { foo: 'bar', type: 1 }

pagination.add({ foo: 'bar', type: 3 }, { foo: 'bar', type: 4 });
console.log(pagination.pages); // output: [...]

RemoveAcents

Use this function to remove unwanted characters.

If you want to inspect the code, click here.

import { removeAcents } from 'bucky.js';
console.log(removeAcents('Fõò, Bãr'));

RemoveArrayDuplicates

Use this function to remove repeated strings within an Array.

If you want to inspect the code, click here.

import { removeArrayDuplicates } from 'bucky.js';

let list = ['foo', 'bar', 'foo'];
console.log(removeArrayDuplicates(list)); // output: ['foo', 'bar']

RemoveDupleChars

Use this function to remove repeated letters from a string.

If you want to inspect the code, click here.

import { removeDupleChars } from 'bucky.js';

let text = 'aaaaaaaaa bbbbbbbb';
console.log(removeDupleChars(text)); // output: 'a b'
console.log(removeDupleChars(text, 2)); // output: 'aa bb'

Shorten

Use this function to limit the characters of a text.

If you want to inspect the code, click here.

import { shorten } from 'bucky.js';

let text = 'your text 297483930293';
console.log(shorten(text, 9)); // output: your text...

SimilarString

Use this function to find a string similar to another.

If you want to inspect the code, click here.

import { similarString } from 'bucky.js';

let name = 'bucky',
  listNames = ['isBucky', '7Silva', '7ohn'],
  search = similarString(name, listNames);
  
console.log(search); // output: {
//  ratings: [
//    { target: 'isBucky', rating: 0.8451542547285165, index: 0 },
//    { target: '7Silva', rating: 0, index: 1 },
//    { target: '7ohn', rating: 0, index: 2 }
//  ],
//  result: { target: 'isBucky', rating: 0.8451542547285165, index: 0 }
//}

Sleep

Use this function to create a "sleep", to make the code below run after the given time.

If you want to inspect the code, click here.

import { sleep } from 'bucky.js';

(async() => {
  console.log('foo');
  await sleep(5000); // Sets the time in milliseconds
  console.log('bar');
})();