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

@frankkai/u-js

v0.1.3

Published

Useful javascript library across Browser and Node.js.

Downloads

5

Readme

中文文档 英文文档

u-js

Useful javascript library across Browser and Node.js.

  • Support for Browser and Node.js
  • Common type checks utils
  • Common audio processing utils
  • Common blob processing utils
  • Common task flow control utils
  • Common timer trick utils

Install

// if you have installed yarn
$ yarn add @frankkai/u-js

// npm is also a choice
$ npm install @frankkai/u-js

Features

  • Type Check
  • Audio Processing
  • Blob Processing
  • Task flow control
  • Timer trick

Type Check

isString
isNumber
isBoolean
isUndefined
isNull
isNaN
isArray
isFunction
isDate
isRegExp
isError
isPromise
isSymbol
isBigInt
isMap
isSet
isWeakMap
isWeakSet
isArrayBuffer
isFormData
isBlob
isFile
isURLSearchParams
isObject
isJSON
Examples
// Browser Environment
import { type as typeUtils } from "@frankkai/u-js";

const isStringTest = typeUtils.isString("Yes, I'm a string.");
console.log(isStringTest); // true

// Node.js Environment
const { type } = require("@frankkai/u-js");

const isStringTest = type.isString("Yes, I'm a string.");
console.log(isStringTest); // true

const isNumberTest = type.isNumber("No, I'm a string.");
console.log(isNumberTest); // false

Audio Processing

  • getAudioDuration(source)
    • source
      • { File | Blob | Url } Browser
      • { Url | Path } Node.js
Examples
// Browser Environment
import { audio as audioUtils } from "@frankkai/u-js";

audioUtils
  .getAudioDuration("https://foo.bar.baz.com/996.mp3")
  .then(duration => {
    console.log(duration);
  });
// Node.js Environment
const { audio } = require("@frankkai/u-js");

audio.getAudioDuration("../996.mp3").then(duration => {
  console.log(duration);
});

Blob Processing

  • transferBlobFileToBase64(source)
    • source
      • { File | Blob } Browser
      • { ArrayBuffer } Node.js
Examples
// Browser Environment
import { blob as blobUtils } from "@frankkai/u-js";

const blobObj = new Blob(["hello world"], { type: "text/plain" });
blobUtils.transferBlobFileToBase64(blobObj).then(base64Str => {
  console.log(base64Str);
});

// Node.js Environment
const { blob } = require("@frankkai/u-js");
const fs = require("fs");

const source = fs.readFileSync("./meta.js");

blob.transferBlobFileToBase64(source).then(base64 => {
  console.log(base64);
});

Task flow control

  • parallelFlow(items, asyncFunc)
    • items
    • asyncFunc
Examples
// Node.js Environment
const { task } = require("@frankkai/u-js");

task.parallelFlow(["foo", "bar", "baz"], asyncFunc).then(data => {
  console.log(data); // [ 'hi, foo', 'hi, bar', 'hi, baz' ]
});

function asyncFunc(item) {
  return new Promise(resolve => {
    resolve(`hi, ${item}`);
  });
}

Timer trick

  • evenlySpaced(items, space, callback)
    • items
    • space
    • callback
  • intervalCondition({ watcher, condition, clearTimer, intervalTimer }, callback)
    • watcher
    • condition
    • clearTimer
    • intervalTimer
Examples
// Node.js Environment
const { timer } = require("@frankkai/u-js");

timer.evenlySpaced(["foo", "bar", "baz"], 1000, data => {
  console.log(data); // "foo"  "bar" "baz"
});
// Node.js Environment
const { timer } = require("@frankkai/u-js");
let foo = { initial: 1, target: 10 };

setTimeout(() => {
  foo.initial = 10;
}, 1000);

timer.intervalCondition(
  {
    watcher: foo,
    condition: "watcher.initial === watcher.target",
    clearTimer: 100,
    intervalTimer: 1000
  },
  data => {
    console.log(data); // true
  }
);