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

azheda-utils

v1.0.4

Published

| [Server-Side](#for-node) | [Client-Side](#client) | |:--------------------------------------------:|:----------------------------------------:| | [Installation](#install) | [Installation](#inst

Downloads

12

Readme

For node

| Server-Side | Client-Side | |:--------------------------------------------:|:----------------------------------------:| | Installation | Installation | | Usage | myStorage | | Sleep function | Loader | | Download file from url | Number.map | | WebServer | Number.getid | | MySurreal | String.encodeAscii | | CheckTime | String.decodeAscii | | | String.hashSeed | | | String.getid | | | String.capitalize | | | Array.copy | | | Array.randomize | | | Array.sortByList | | | Object.copy | | | Object.sort | | | Object.getList |

Install

npm install azheda-utils

Usage

const azhedautils = require('azheda-utils');

Sleep function

await azhedautils.sleep(1000);

This will stop the code for 1000ms (1 second)

Download function

Download a file from a url

await azhedautils.downloadFile(url, filename);

This function will download a file from a url and save it with a specific filename.

WebServer

const server = new azhedautils.WebServer({
	host: 'localhost',
	port: 7788
});

This function will start a webserver, the default command are limited.

MySurreal

// method 1:
const mysur = new azhedautils.MySurreal();
mysur.setUser('<your username>', '<your password>');
mysur.setNamespace('<namespace>');
mysur.setDatabase('<database>');

// method 2:
const mysur = new azhedautils.MySurreal({
  username: '<your username>',
  password: '<your password>',
  namespace: '<namespace>',
  database: '<database>',
  // You can also use custom host, port and path, these are the default for SurrealDB, you can ignore them if you want
  host: '127.0.0.1',
  port: 8000,
  path: 'rpc'
});


// Querys:
await mysur.query('...'); // Any surreal query
await mysur.create('person:toby', { name: 'Toby', age: 20 });
await mysur.insert('person', [{ name: 'Toby', age: 20 }, { name: 'Derek', age: 30 }])
await mysur.patch('person:toby', { age: 25 });
await mysur.delete('person:toby');
await mysur.live('person');
await mysur.kill('<surreal query uuid>');
await mysur.close();

CheckTime

Once you've asign the new instance of the class to a variable, you just need to call .set() to save the current time

const chTime = new azhedautils.CheckTime();

(async () => {
	chTime.set();
	await azhedautils.sleep(4 * 1000) // 4 Seconds written in milliseconds
	console.log(chTime.set()+'ms');
	>>> 4004ms
})();

Client

Installation:

<script src="https://unpkg.com/azheda-utils/dist/client.js"></script>

Class myStorage

const testValue = 123;
const testKey = 't-key';
const time = 1000 * 60 * 60; // 1 hour in milliseconds

Add value 123 to localStorage with 't-key' as key, return true if the the value was set correctly, false or null otherwise

myStorage.add(testKey, testValue);

Checks if there's that key saved in localStorage and return the value, if the key was not found, that returns null

myStorage.get(testKey);

If a value is saved in localStorage with that key, the value'll be removed, return true if this was successful, false if there was some kind of problem

myStorage.remove(testKey);

Clear all data saved in localStorage, returns 0 if everything was cleared correctly

myStorage.clear();

Same as myStorage.add(), but this time, the value has an expiry time.

myStorage.localcookie.set(testKey, testValue, time);

This function'll try to read and the value with the given key saved in localStorage. if the key was not found this'll return null. if the expiry time was passed, the value will'be cleared and this'll return null.

myStorage.localcookie.get(key);

Class Loader:

const theme = 'dark'; // or 'light'
const loader = new Loader(theme);
loader.append(); // -> Add the loader in the center of the window
loader.remove(); // -> Remove the loader

New properties (added with prototype):

Number.map

This will convert the number from the first range of numbers to the second one

const testNumber = 7;
console.log(testNumber.map(0, 10, 0, 100));
>>> 70

Number.getid

const myNumber = 123;

console.log(myNumber.getid());
>>> 3050889136

String.encodeAscii

const testString = 'Hello';

const asciiString = testString.encodeAscii();
console.log(asciiString);
>>> 72|101|108|108|111

String.decodeAscii

const testString = '72|101|108|108|111';
console.log(testString.decodeAscii());
>>> Hello

String.hashSeed

const testString = 'Hello';
console.log(testString.hashSeed());
>>> 4867314475583282
console.log(testString.hashSeed(1));
>>> 7386249923560166
console.log(testString.hashSeed(2));
>>> 715765420405280

String.getid

const myString = 'Hello';

console.log(myString.getid());
>>> 1987897324

String.capitalize

console.log('hello'.capitalize());
>>> Hello
console.log('Hello world'.capitalize());
>>> Hello world

Array.copy

Create a deepcopy of the array

const myList = [1, 2, 3];

console.log(myList.copy());
>>> [1, 2, 3]

Array.randomize

This function will return a copy of the array but every item has a new random index

const arr = [1, 2, 3, 4, 5];
console.log(arr.randomize());
>>> [5, 3, 1, 4, 2]
console.log(arr.randomize());
>>> [5, 1, 3, 2, 4]
console.log(arr.randomize());
>>> [1, 4, 5, 2, 3]
console.log(arr.randomize());
>>> [1, 3, 5, 2, 4]

Array.sortByList

This function will sort A-Z the array, and then put the given values at the start (in the same order)

const arrayToSort = [
  'dog', 'cat', 'shark',
  'parrot', 'giraffe',
  'zebra', 'dolphin'
];
const newList = arrayToSort.sortByList(['zebra', 'dolphin']);
console.log(newList);
>>> ['zebra', 'dolphin', 'dog', 'cat', 'giraffe', 'parrot', 'shark']

Object.copy

Create a deepcopy of the object


const myObject = { x: 1, y: 2 };

console.log(myObject.copy());
>>> { x: 1, y: 2 }

Object.sort:

const obj = {
  i: 1,
  a: 2,
  z: 3,
  y: 4
};
console.log(obj.sort());
>>> { a: 2, i: 1 y: 4, z: 3 }

Object.getList

const obj = {
  x: 1,
  y: 2,
  z: 3
};

console.log(obj.getList());
>>> [ ['x', 'y', 'z'], [ 1 ,  2 ,  3 ] ]

Dependencies