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

@ircam/sc-utils

v1.3.3

Published

Set of simple generic utilities (type check, common math functions, etc.)

Downloads

356

Readme

@ircam/sc-utils

Simple generic utilities (type check, common math functions, etc.)

Install

npm install --save @ircam/sc-utils

API

Table of Contents

atodb

Convert a linear gain into dB

Alias: linearToDecibel

Parameters

Examples

import { atodb } from '@ircam/sc-utils';
atodb(0);
// > 1

Returns number

dbtoa

Convert a dB into linear gain

Alias: decibelToLinear

Parameters

Examples

import { dbtoa } from '@ircam/sc-utils';
dbtoa(0);
// > 1

Returns number

decibelToLinear

Convert a dB into linear gain (i.e. gain)

Alias: dbtoa

Parameters

Examples

import { decibelToLinear } from '@ircam/sc-utils';
decibelToLinear(0);
// > 1

Returns number

decibelToPower

Convert a dB into power gain

Parameters

Examples

import { decibelToPower } from '@ircam/sc-utils';
decibelToPower(0);
// > 1

Returns number

delay

Wait for a given number of milliseconds.

See also sleep

Parameters

  • ms Number Number of milliseconds to wait

Examples

import { delay } from '@ircam/sc-utils';
// wait for 1 second
await delay(1000);

Returns Promise

ftom

Convert a frequency in Hz to a MIDI note

Parameters

  • freq number Frequency to convert

Examples

import { ftom } from '@ircam/sc-utils';
const freq = ftom(440);
// > 69

Returns number

getTime

Provide a unified clock in seconds accross platforms, with an origin defined by the start of the process.

Examples

import { getTime } from '@ircam/sc-utils';

setInterval(() => {
  const now = getTime();
  // ...
}, 1000)

hertzToNormalised

Convert a frequency in Hertz to a normalised one in [0, 1].

Normalised frequency of 1 is half the sample-rate (Nyquist frequency).

Parameters

  • frequencyHertz number Frequency in Hertz to convert

  • sampleRate number Twice the Nyquist frequency (optional, default {})

    • sampleRate.sampleRate (optional, default 2)

Examples

import { hertzToNormalised } from '@ircam/sc-utils';
hertzToNormalised(12000, {sampleRate: 48000});
// > 0.5

Returns number

idGenerator

Create a iterator of incrementing ids

Examples

import { idGenerator } from '@ircam/sc-utils';
const generator = idGenerator();
const id = generator.next().value

Returns Iterator

isBrowser

Check if the platform is a browser or a node process

Examples

import { isBrowser } from '@ircam/sc-utils';
isBrowser();
// > true|false

Returns boolean

isFunction

Check if the value is a function

Parameters

  • val any Value to check

Examples

import { isFunction } from '@ircam/sc-utils';
isFunction(() => {});
// > true

Returns boolean

isNumber

Check if the value is a number, including Infinity. If you want to excluse Infinity, check the native Number.isFinite function

Parameters

  • val any Value to check

Examples

import { isNumber } from '@ircam/sc-utils';
isNumber(42);
// > true

Returns boolean

isPlainObject

Check if the value is a Plain Old Javascript Object (POJO)

Parameters

  • val any Value to check

Examples

import { isObject } from '@ircam/sc-utils';
isObject({ a: 1 });
// > true

Returns boolean

isString

Check if the value is a string

Parameters

  • val any Value to check

Examples

import { isString } from '@ircam/sc-utils';
isString('test');
// > true

Returns boolean

isTypedArray

Check if the value is a TypedArray

Parameters

  • val any Value to check

Examples

import { isTypedArray } from '@ircam/sc-utils';
isTypedArray(new Float32Array([1, 2, 3]));
// > true

Returns boolean

linearScale

Create a scale function

Parameters

  • minIn number Minimum input
  • maxIn number Maximum input
  • minOut number Minimum output
  • maxOut number Maximum output
  • clamp boolean Clamp output (optional, default false)

Examples

import { scale } from '@ircam/sc-utils';
const myScale = scale(0, 1, 50, 100);
myScale(0.5);
// > 75

Returns Function

linearToDecibel

Convert a linear gain into dB

Alias: atodb

Parameters

Examples

import { decibelToPower } from '@ircam/sc-utils';
decibelToPower(0);
// > 1

Returns number

mtof

Convert a MIDI note to frequency

Parameters

  • midiNote number MIDI Note to convert

Examples

import { mtof } from '@ircam/sc-utils';
const freq = mtof(69);
// > 440

Returns number

normalisedToHertz

Convert a normalised frequency, in [0, 1], to a frequency in Hertz.

Normalised frequency of 1 is half the sample-rate (Nyquist frequency).

Parameters

  • frequencyNormalised number Normalised frequency to convert

  • sampleRate number Twice the Nyquist frequency (optional, default {})

    • sampleRate.sampleRate (optional, default 2)

Examples

import { normalisedToHertz } from '@ircam/sc-utils';
normalisedToHertz(0.5, {sampleRate: 48000});
// > 12000

Returns number

powerToDecibel

Convert a linear gain into dB

Parameters

Examples

import { decibelToPower } from '@ircam/sc-utils';
decibelToPower(0);
// > 1

Returns number

sleep

Wait for a given number of seconds.

See also delay

Parameters

  • sec Number Number of seconds to wait

Examples

import { sleep } from '@ircam/sc-utils';
// wait for 1 second
await sleep(1);

Returns Promise

License

BSD-3-Clause