Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ircam/sc-utils

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ircam/sc-utils

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

  • 1.3.0
  • npm
  • Socket score

Version published
Weekly downloads
159
increased by657.14%
Maintainers
3
Weekly downloads
 
Created
Source

@ircam/sc-utils

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

Install

npm install --save @ircam/sc-utils

API

Constants

isBrowserboolean

Check if the platform is a browser or a node process

Functions

delay(ms)Promise

Waits for given number of milliseconds

sleep(sec)Promise

Same of delay, but given argument is in seconds

isString(val)boolean

Check if the value is a string

isFunction(val)boolean

Check if the value is a function

isNumber(val)boolean

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

isPlainObject(val)boolean

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

isTypedArray(val)boolean

Check if the value is a TypedArray

dbtoa(val)number

Convert a dB into linear gain (i.e. gain) Alias: decibelToLinear

decibelToLinear(val)number

Convert a dB into linear gain (i.e. gain) Alis: dbtoa

decibelToPower(val)number

Convert a dB into power gain

atodb(val)number

Convert a linear gain into dB Alias: linearToDecibel

linearToDecibel(val)number

Convert a linear gain into dB Alias: atodb

powerToDecibel(val)number

Convert a linear gain into dB

mtof(midiNote)number

Convert a MIDI note to frequency

ftom(freq)number

Convert a frequency to a MIDI note

linearScale(minIn, maxIn, minOut, maxOut, [clamp])function

Create a scale function

idGenerator()Iterator

Create a iterator of incrementing ids

isBrowser ⇒ boolean

Check if the platform is a browser or a node process

Kind: global constant
Example

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

delay(ms) ⇒ Promise

Waits for given number of milliseconds

Kind: global function

ParamTypeDescription
msNumberNumber of milliseconds to wait

Example

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

sleep(sec) ⇒ Promise

Same of delay, but given argument is in seconds

Kind: global function

ParamTypeDescription
secNumberNumber of seconds to wait

Example

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

isString(val) ⇒ boolean

Check if the value is a string

Kind: global function

ParamTypeDescription
val*Value to check

Example

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

isFunction(val) ⇒ boolean

Check if the value is a function

Kind: global function

ParamTypeDescription
val*Value to check

Example

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

isNumber(val) ⇒ boolean

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

Kind: global function

ParamTypeDescription
val*Value to check

Example

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

isPlainObject(val) ⇒ boolean

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

Kind: global function

ParamTypeDescription
val*Value to check

Example

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

isTypedArray(val) ⇒ boolean

Check if the value is a TypedArray

Kind: global function

ParamTypeDescription
val*Value to check

Example

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

dbtoa(val) ⇒ number

Convert a dB into linear gain (i.e. gain) Alias: decibelToLinear

Kind: global function

ParamTypeDescription
valnumberValue to convert

Example

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

decibelToLinear(val) ⇒ number

Convert a dB into linear gain (i.e. gain) Alis: dbtoa

Kind: global function

ParamTypeDescription
valnumberValue to convert

Example

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

decibelToPower(val) ⇒ number

Convert a dB into power gain

Kind: global function

ParamTypeDescription
valnumberValue to convert

Example

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

atodb(val) ⇒ number

Convert a linear gain into dB Alias: linearToDecibel

Kind: global function

ParamTypeDescription
valnumberValue to convert

Example

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

linearToDecibel(val) ⇒ number

Convert a linear gain into dB Alias: atodb

Kind: global function

ParamTypeDescription
valnumberValue to convert

Example

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

powerToDecibel(val) ⇒ number

Convert a linear gain into dB

Kind: global function

ParamTypeDescription
valnumberValue to convert

Example

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

mtof(midiNote) ⇒ number

Convert a MIDI note to frequency

Kind: global function

ParamTypeDescription
midiNotenumberMIDI Note to convert

Example

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

ftom(freq) ⇒ number

Convert a frequency to a MIDI note

Kind: global function

ParamTypeDescription
freqnumberFrequency to convert

Example

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

linearScale(minIn, maxIn, minOut, maxOut, [clamp]) ⇒ function

Create a scale function

Kind: global function

ParamTypeDefaultDescription
minInnumberMinimum input
maxInnumberMaximum input
minOutnumberMinimum output
maxOutnumberMaximum output
[clamp]booleanfalseClamp output

Example

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

idGenerator() ⇒ Iterator

Create a iterator of incrementing ids

Kind: global function
Example

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

License

BSD-3-Clause

FAQs

Package last updated on 07 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc