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

darkness-tools

v3.5.16

Published

Simple tools

Downloads

85

Readme

Using

Darkness Tools is a Node.JS module, that provides convenient functions, that make coding easier.

P.S. There will be no conflicts with native methods in new methods of global classes - if one of them already exists, it will not be replaced by a new one

Installation

npm i darkness-tools 

or using yarn:

yarn add darkness-tools 

Usage

import tools from 'darkness-tools'

Methods

random(min, max)

Returns random entities

tools.random(10) // random integer between 0 and 10
tools.random(10, 100) // random integer between 10 and 100

tools.randomBoolean() // randomly true or false

tools.random([...]) // random element from array

tools.random({...}) // random key from object

timeInMs

Returns object with time frames in milliseconds

Available millisecond, second, minute, hour and day

tools.timeInMs.hour // 3600000

tools.timeInMs.day // 86400000

updateClasses(...prototypes)

Function that adds new method to global classes

Available String, Array, Object, Number and Date methods

// Give all prototypes of available classes in which u want to add new methods

tools.updateClasses(Date.prototype, Number.prototype, Array.prototype) // updates Date, Number and Array classes

Methods of updated classes

String

replaceAll(substring, replacer)

Returns a new string with all matches of a pattern or substring replaced by a replacement

'Round apples and juicy Apples'.replaceAll(/apples/gi, 'oranges') // Round oranges and juicy oranges

'Round apples and juicy apples'.replaceAll('apples', 'oranges') // Round oranges and juicy oranges

deleteAll(substring)

Returns a new string with deleted all matches of a pattern or substring

'Darkness tools is not the best'.deleteAll('not') // Darkness tools is the best

setData(data)

Returns a new string with replaced %key% with specified value

const user = {
    name: 'John',
    age: 20
}
'My name is %name%, I am %age% y.o.'.setData(user) // My name is John, I am 20 y.o

firstToUpperCase()

Returns a new string with first symbol at upper case

'darkness'.firstToUpperCase() // Darkness

toBoolean()

Converts string to boolean

'true'.toBoolean() // true

'0'.toBoolean() // false

'str'.toBoolean() // true

Array

randomElement()

Returns random element from array

[1, 2, 3].randomElement() // Randomly 1, 2 or 3

const names = ['Jonh', 'Helen', 'Fluffy']
name.randomElement() // Random name from names

lastElement()

Returns last element from array

[1, 2, 3].lastElement() // 3

const names = ['Jonh', 'Helen', 'Fluffy']
names.lastElement() // Fluffy

removeElement(element)

Removes specified element from array Note, that this will not work with arrays and objects

[5, 4, 3, 2, 1].removeElement(2) // [5, 4, 3, 1]

const names = ['Jonh', 'Helen', 'Fluffy']
names.removeElement('Helen') // ['John', 'Fluffy']

sum()

Returns sum of all elements of array

[5, 4, 3, 2, 1].sum() // 15

[18, 2, 5, '$'].sum() // 25$

Number

in_range(a, b)

Returns true or false corresponding to the existence of a number in the interval [a;b]

const number = 115

number.in_range(0, 100) // false
number.in_range(0, 200) // true
number.in_range(100, 115) // true

Object

toShowString()

Converts object to string, placing tabs

const user = {
    name: 'Fluffy',
    age: 20,
    friends: ['John', 'Helen']
}
//native method:
JSON.stringify(user)  // "{"name":"Fluffy","age":20,"friends":["John","Helen"]}"

//new method
user.toShowString() // result will be:
{
    "name": "Fluffy",
    "age": 20,
    "friends": [
        'John',
        'Helen'
    ]
}

createCopy()

Returns a copy of object. Also, all values of keys of object will be also copies, not a links to it Note, that all class instances will be converted to simple Objects

const user1 = {
    name: 'Fluffy',
    age: 20,
    friends: ['John', 'Helen']
}

const user2 = user1
user1.age++
user2.age // 21 intead of 20

// copying  with new method
const user2 = user1.createCopy()
user1.age++
user1.age // 21
user2.age // 20

Date

leftTimeTo(date)

Returns object with time to specified date in days, hours, minutes, seconds and milliseconds

const date = new Date('December 02, 2020 12:36:11:16'),
    nextDate = new Date('December 31, 2020 24:00:00:00')
    
date.leftTimeTo(nextDate) // { days: 29, hours: 11, minutes: 23, seconds: 48, milliseconds: 984 }

License

MIT