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 🙏

© 2025 – Pkg Stats / Ryan Hefner

useful-js-ibrary

v2.1.0

Published

create a collection of useful js function solution

Readme

Useful-JS-Function

This is a simple library contain different kind of useful function.

Install

npm install --save useful-js-ibrary

TIME API

.get_timezones()

Returns a array of all the timezones.

Example

const Times = require('useful-js-ibrary').Times;

const timezones = Times.get_timezones();

.current_location_time(type,option,timezone_name)

Returns a string base on the parameter.

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | type | string | require | time / date / full | | optoin | object | require | addition condition to render date string | | timezone_name | string | require | "" or timezone from .get_timezones() |

optoin parameter

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | time_format | string | "24" | "12" / "24" | | separators | string | "/" | any string to sperate the date ex. 02/25/2020 with "/" | | order | array | ["mm","dd","yyyy"] | date string order included "m", "mm", "mmm", "d", "dd", "yy","yyyy"|

Example

const Times = require('useful-js-ibrary').Times;

const timezones = Times.current_location_time("full",{time_format:"12",separators:"/",order:["mmm","dd","yyyy"]},"Asia/Taipei");

// output => 'Feb/29/2020 07:21:21 AM'

Chat Room function

Server

Bind the express server or port number on the Socket.

Example

var app = require('express')();

var http = require('http').createServer(app);

var Socket_Server = require('useful-js-ibrary').Socket_Server;

var Server = new Socket_Server(http);

Client

Initial the Client with register ID, option, extend data, callback function

Initial parameter

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | id | string | require | register ID in your local system. | | optoin | object | require | option for setting socket. | | optoin.url | string | ------- | IP address sockect binding to. | | extend | object | require | extend data field with user. | | callback | function | require | callback function when the client receiving message. |

Socket Flow

  1. Connect to the Server and Complete the initial process.
var Socket_Client = require('useful-js-ibrary').Socket_Client;

var Socket = new Socket_Client('developer_id',{url:'http://localhost'},{},(msg) => {console.log(msg)});

/* => registered message
{
    type : 'Initial',
    from_id : 'system',
    message : 'developer_id is Registered'
}
*/
  1. After receiving registered message, start to handle four types of message.

    • Handshake : Comfirm the user Status.
    • Chat : Sending Message to the user.
    • Typing : Sending typing message signal to the user.
    • Users : Get all the current online users.
Sending

// Handshake
Socket.Handshake('user_id');

// Chat
Socket.Chat('user_id','Hello World');

// Typing
Socket.Typing('user_id','user is typing');

// Users
Socket.Users();

// Broadcast
Socket.Broadcast('Hello World');

// Disconnect
Socket.Disconnect();
Receiving
Message received will forward to callback function.

| Attribute | Type | Value | | --------- | ---- | ----------- | | type | string | Handshake / Chat / Typing / Users | | from_id | string | The id it send from. (Empty when calling Users) | | message | string | Handshake : Online / Offline. | | ------- | ------ | Chat : Message from the user. | | ------- | ------ | Typing : Empty. | | ------- | ------ | Users : Empty. | | users | array | retrun array of users (Users only) |