mxtorie-utils

1.0.1 • Public • Published

mxtorie-utils

For any question or support request : discord Other utils npm :

  • luma-db Like quick.db more advanced and online storage
  • mxtorie Advanced optimised mysql database managing

Features :

  • Collection
  • Print (replace console.log)
  • Sleep (replace setTimeout)
  • dateToEpoch (return a data to timestamp)
  • randomChar (return a random string)
  • randomNumber (return a random number)
  • isLink (check if the text contain a link)
  • toJSON (return a object to json)

Examples :

Print :

const {print} = require('mxtorie-utils')
print('hello') // will print 'hello' in the console
// print replace console.log

To use print anywhere :

global.print = require('mxtorie-utils').print
// you can now use print() in all files without import it

Sleep :

const {print, sleep} = require('mxtorie-utils')
print('hello')
await sleep(2000) // await is VERY important !
print('hello 2 seconds after')

Collection :

  • Not all features will be showed.
const {Collection, print} = require('mxtorie-utils')
const data = new Collection() //you can set a default value (object) in the ()

data.set('key1', 1) //set 1 in the collection where the key is 'key1'
print(data.get('key1')) // 1
print(data.has('key1')) // true
data.set('key2', 2) //set 2 in the collection where the key is 'key2'
let allData = data.all()
print(allData) // [{key: 'key1', data: 1}, {key: 'key2', data: 2}]

print(data.first()) // 1
print(data.firstKey()) // key1
print(data.last()) // 2
print(data.lastKey()) // key2
print(data.at(1)) // 2
print(data.keyAt(1)) // key2

data.clear() // clear the collection
data.set('firstKey', 1).set('secondKey', 2)
print(data.all()) // [{key: 'firstKey', data: 1}, {key: 'secondKey', data: 2}]
data.reverse() //reverse the collection
print(data.all()) // [{key: 'secondKey', data: 2}, {key: 'firstKey', data: 1}]

let find = data.find(v => v === 2)
print(find) // [ 2 ]
let findComplete = data.find(v => v === 2, true)
print(findComplete) // [{key: 'secondKey', data: 2}]
let findOne = data.findOne(v => v === 2)
print(findOne) // 2
let findOneComplete = data.findOne(v => v === 2)
print(findOneComplete) // {key: 'secondKey', data: 2}

print(data.filter(v => v === 2).all()) // [{key: 'secondKey', data: 2}]
data.delete('secondKey') // will delete the value where key is 'secondKey'

data.save('./mySave.json') // will save all data of the collection
print(data.all()) // [{key: 'firstKey', data: 1}, {key: 'secondKey', data: 2}]
let newData = new Collection()
newData.getSave('./mySave.json')
print(newData.all()) // [{key: 'firstKey', data: 1}, {key: 'secondKey', data: 2}]

let perfectClone = data.clone()
print(perfectClone) // [{key: 'firstKey', data: 1}, {key: 'secondKey', data: 2}]

/* AND MORE... LIKE FOREACH, MAP, ETC... */

isLink :

const {print, isLink} = require('mxtorie-utils')
print(isLink('hello its me')) // false
print(isLink('https://discord.gg/mxtorie')) // true

And more functions ...

Package Sidebar

Install

npm i mxtorie-utils

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

24.4 kB

Total Files

5

Last publish

Collaborators

  • jeotique