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

bitdepth

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitdepth - npm Package Compare versions

Comparing version 5.0.0 to 6.0.0

dist/bitdepth.browser.js

5

CHANGELOG.md
# CHANGELOG
## v6.0.0 (2018-06-25)
- Allow better use of this lib as a dependency:
- package.json refactored with bundlers and ES6 envs in mind
- bitdetph function exported as default
## 5.0.0 (2018-06-22)

@@ -4,0 +9,0 @@ - ES6 module.

76

dist/bitdepth.cjs.js

@@ -1,73 +0,3 @@

(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
'use strict';
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (immutable) */ __webpack_exports__["bitdepth"] = bitdepth;
/*

@@ -246,4 +176,2 @@ * bitdepth: Change the resolution of samples to and from any bit depth.

/***/ })
/******/ ])));
module.exports = bitdepth;

@@ -1,5 +0,7 @@

var h="function"==typeof Object.defineProperties?Object.defineProperty:function(c,b,a){c!=Array.prototype&&c!=Object.prototype&&(c[b]=a.value)},m="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function n(c,b){if(b){var a=m;c=c.split(".");for(var d=0;d<c.length-1;d++){var e=c[d];e in a||(a[e]={});a=a[e]}c=c[c.length-1];d=a[c];b=b(d);b!=d&&null!=b&&h(a,c,{configurable:!0,writable:!0,value:b})}}
n("Object.is",function(c){return c?c:function(b,a){return b===a?0!==b||1/b===1/a:b!==b&&a!==a}});n("Array.prototype.includes",function(c){return c?c:function(b,a){var d=this;d instanceof String&&(d=String(d));var c=d.length;a=a||0;for(0>a&&(a=Math.max(a+c,0));a<c;a++){var g=d[a];if(g===b||Object.is(g,b))return!0}return!1}});
window.bitdepth=function(c){function b(d){if(a[d])return a[d].a;var e=a[d]={v:d,j:!1,a:{}};c[d].call(e.a,e,e.a,b);e.j=!0;return e.a}var a={};b.u=c;b.m=a;b.h=function(d,a){b.i(d)||Object.defineProperty(d,"a",{configurable:!1,enumerable:!0,get:a})};b.o=function(a){var c=a&&a.l?function(){return a["default"]}:function(){return a};b.h(c,c);return c};b.i=function(a){return Object.prototype.hasOwnProperty.call(a,"a")};b.s="";return b(b.w=0)}([function(c,b){function a(a,b){return a=0<a?parseInt(a/b.f*b.b,
10):parseInt(a/b.g*b.c,10)}function d(a,b){return parseInt(0<a?a*b.b:a*b.c,10)}function e(a,b){return 0<a?a/b.f:a/b.g}function g(a){k[0]=a;return k[0]}function p(b,c){function f(a){return a}b!=c&&(["32f","64"].includes(b)?["32f","64"].includes(c)?f=g:f=d:f=["32f","64"].includes(c)?e:a);return f}function l(a){if("32f"!=a&&"64"!=a&&("8">parseInt(a,10)||"53"<parseInt(a,10)))throw Error("Invalid bit depth.");}Object.defineProperty(b,"__esModule",{value:!0});b.bitdepth=function(a,b,c,d){l(b);l(c);d=d||
a;var e=p(b,c),g={g:Math.pow(2,parseInt(b,10))/2,c:Math.pow(2,parseInt(c,10))/2,f:Math.pow(2,parseInt(b,10))/2-1,b:Math.pow(2,parseInt(c,10))/2-1},f=a.length;if("8"==b)for(b=0;b<f;b++)d[b]=a[b]-=128;for(b=0;b<f;b++)d[b]=e(a[b],g);if("8"==c)for(a=0;a<f;a++)d[a]=d[a]+=128};var k=new Float32Array(1)}]);
var f="function"==typeof Object.defineProperties?Object.defineProperty:function(d,c,a){d!=Array.prototype&&d!=Object.prototype&&(d[c]=a.value)},g="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function k(){k=function(){};g.Symbol||(g.Symbol=n)}var n=function(){var d=0;return function(c){return"jscomp_symbol_"+(c||"")+d++}}();
function p(d,c){if(c){var a=g;d=d.split(".");for(var b=0;b<d.length-1;b++){var e=d[b];e in a||(a[e]={});a=a[e]}d=d[d.length-1];b=a[d];c=c(b);c!=b&&null!=c&&f(a,d,{configurable:!0,writable:!0,value:c})}}p("Object.is",function(d){return d?d:function(c,a){return c===a?0!==c||1/c===1/a:c!==c&&a!==a}});
p("Array.prototype.includes",function(d){return d?d:function(c,a){var b=this;b instanceof String&&(b=String(b));var e=b.length;a=a||0;for(0>a&&(a=Math.max(a+e,0));a<e;a++){var d=b[a];if(d===c||Object.is(d,c))return!0}return!1}});
window.bitdepth=function(d){function c(b){if(a[b])return a[b].a;var e=a[b]={v:b,j:!1,a:{}};d[b].call(e.a,e,e.a,c);e.j=!0;return e.a}var a={};c.u=d;c.l=a;c.d=function(b,a,d){c.i(b,a)||Object.defineProperty(b,a,{enumerable:!0,get:d})};c.r=function(b){k();k();"undefined"!==typeof Symbol&&Symbol.toStringTag&&(k(),Object.defineProperty(b,Symbol.toStringTag,{value:"Module"}));Object.defineProperty(b,"__esModule",{value:!0})};c.s=function(b,a){a&1&&(b=c(b));if(a&8)return b;if(a&4&&"object"===typeof b&&b&&
b.h)return b;var d=Object.create(null);c.r(d);Object.defineProperty(d,"default",{enumerable:!0,value:b});if(a&2&&"string"!=typeof b)for(var e in b)c.d(d,e,function(c){return b[c]}.bind(null,e));return d};c.m=function(b){var a=b&&b.h?function(){return b["default"]}:function(){return b};c.d(a,"a",a);return a};c.i=function(b,a){return Object.prototype.hasOwnProperty.call(b,a)};c.o="";return c(c.w=0)}([function(d,c,a){function b(b,a,c,d){l(a);l(c);d=d||b;var u=v(a,c),e={g:Math.pow(2,parseInt(a,10))/2,
c:Math.pow(2,parseInt(c,10))/2,f:Math.pow(2,parseInt(a,10))/2-1,b:Math.pow(2,parseInt(c,10))/2-1},h=b.length;if("8"==a)for(a=0;a<h;a++)d[a]=b[a]-=128;for(a=0;a<h;a++)d[a]=u(b[a],e);if("8"==c)for(b=0;b<h;b++)d[b]=d[b]+=128}function e(a,b){return a=0<a?parseInt(a/b.f*b.b,10):parseInt(a/b.g*b.c,10)}function q(a,b){return parseInt(0<a?a*b.b:a*b.c,10)}function r(a,b){return 0<a?a/b.f:a/b.g}function t(a){m[0]=a;return m[0]}function v(a,b){function c(a){return a}a!=b&&(["32f","64"].includes(a)?["32f","64"].includes(b)?
c=t:c=q:c=["32f","64"].includes(b)?r:e);return c}function l(a){if("32f"!=a&&"64"!=a&&("8">parseInt(a,10)||"53"<parseInt(a,10)))throw Error("Invalid bit depth.");}a.r(c);a.d(c,"default",function(){return b});var m=new Float32Array(1)}]);window.bitdepth=window.bitdepth.default;

@@ -1,259 +0,182 @@

(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["bitdepth"] = factory();
else
root["bitdepth"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.bitdepth = factory());
}(this, (function () { 'use strict';
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (immutable) */ __webpack_exports__["bitdepth"] = bitdepth;
/*
* bitdepth: Change the resolution of samples to and from any bit depth.
* https://github.com/rochars/bitdepth
*
* Copyright (c) 2017-2018 Rafael da Silva Rocha.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/*
* bitdepth: Change the resolution of samples to and from any bit depth.
* https://github.com/rochars/bitdepth
*
* Copyright (c) 2017-2018 Rafael da Silva Rocha.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @fileoverview The bitdepth() function and private helper functions.
*/
/**
* @fileoverview The bitdepth() function and private helper functions.
*/
/** @module bitdepth */
/** @module bitdepth */
/** @private */
const f64f32_ = new Float32Array(1);
/** @private */
const f64f32_ = new Float32Array(1);
/**
* Change the bit depth of samples. The input array is modified in-place.
* @param {!Array<number>} samples The samples.
* @param {string} original The original bit depth of the data.
* One of "8" ... "53", "32f", "64"
* @param {string} target The desired bit depth for the data.
* One of "8" ... "53", "32f", "64"
* @param {Array<number>=} outputArray An optional array to write
converted samples to. Useful for writing to typed arrays.
*/
function bitdepth(samples, original, target, outputArray) {
validateBitDepth_(original);
validateBitDepth_(target);
outputArray = outputArray || samples;
/** @type {!Function} */
let toFunction = getBitDepthFunction_(original, target);
/** @type {!Object<string, number>} */
let options = {
oldMin: Math.pow(2, parseInt(original, 10)) / 2,
newMin: Math.pow(2, parseInt(target, 10)) / 2,
oldMax: (Math.pow(2, parseInt(original, 10)) / 2) - 1,
newMax: (Math.pow(2, parseInt(target, 10)) / 2) - 1,
};
/** @type {number} */
const len = samples.length;
// sign the samples if original is 8-bit
if (original == "8") {
for (let i=0; i<len; i++) {
outputArray[i] = samples[i] -= 128;
/**
* Change the bit depth of samples. The input array is modified in-place.
* @param {!Array<number>} samples The samples.
* @param {string} original The original bit depth of the data.
* One of "8" ... "53", "32f", "64"
* @param {string} target The desired bit depth for the data.
* One of "8" ... "53", "32f", "64"
* @param {Array<number>=} outputArray An optional array to write
converted samples to. Useful for writing to typed arrays.
*/
function bitdepth(samples, original, target, outputArray) {
validateBitDepth_(original);
validateBitDepth_(target);
outputArray = outputArray || samples;
/** @type {!Function} */
let toFunction = getBitDepthFunction_(original, target);
/** @type {!Object<string, number>} */
let options = {
oldMin: Math.pow(2, parseInt(original, 10)) / 2,
newMin: Math.pow(2, parseInt(target, 10)) / 2,
oldMax: (Math.pow(2, parseInt(original, 10)) / 2) - 1,
newMax: (Math.pow(2, parseInt(target, 10)) / 2) - 1,
};
/** @type {number} */
const len = samples.length;
// sign the samples if original is 8-bit
if (original == "8") {
for (let i=0; i<len; i++) {
outputArray[i] = samples[i] -= 128;
}
}
// change the resolution of the samples
for (let i=0; i<len; i++) {
outputArray[i] = toFunction(samples[i], options);
}
// unsign the samples if target is 8-bit
if (target == "8") {
for (let i=0; i<len; i++) {
outputArray[i] = outputArray[i] += 128;
}
}
}
// change the resolution of the samples
for (let i=0; i<len; i++) {
outputArray[i] = toFunction(samples[i], options);
}
// unsign the samples if target is 8-bit
if (target == "8") {
for (let i=0; i<len; i++) {
outputArray[i] = outputArray[i] += 128;
/**
* Change the bit depth from int to int.
* @param {number} sample The sample.
* @param {!Object<string, number>} args Data about the original and target bit depths.
* @return {number}
* @private
*/
function intToInt_(sample, args) {
if (sample > 0) {
sample = parseInt((sample / args.oldMax) * args.newMax, 10);
} else {
sample = parseInt((sample / args.oldMin) * args.newMin, 10);
}
return sample;
}
}
/**
* Change the bit depth from int to int.
* @param {number} sample The sample.
* @param {!Object<string, number>} args Data about the original and target bit depths.
* @return {number}
* @private
*/
function intToInt_(sample, args) {
if (sample > 0) {
sample = parseInt((sample / args.oldMax) * args.newMax, 10);
} else {
sample = parseInt((sample / args.oldMin) * args.newMin, 10);
/**
* Change the bit depth from float to int.
* @param {number} sample The sample.
* @param {!Object<string, number>} args Data about the original and target bit depths.
* @return {number}
* @private
*/
function floatToInt_(sample, args) {
return parseInt(
sample > 0 ? sample * args.newMax : sample * args.newMin, 10);
}
return sample;
}
/**
* Change the bit depth from float to int.
* @param {number} sample The sample.
* @param {!Object<string, number>} args Data about the original and target bit depths.
* @return {number}
* @private
*/
function floatToInt_(sample, args) {
return parseInt(
sample > 0 ? sample * args.newMax : sample * args.newMin, 10);
}
/**
* Change the bit depth from int to float.
* @param {number} sample The sample.
* @param {!Object<string, number>} args Data about the original and target bit depths.
* @return {number}
* @private
*/
function intToFloat_(sample, args) {
return sample > 0 ? sample / args.oldMax : sample / args.oldMin;
}
/**
* Change the bit depth from int to float.
* @param {number} sample The sample.
* @param {!Object<string, number>} args Data about the original and target bit depths.
* @return {number}
* @private
*/
function intToFloat_(sample, args) {
return sample > 0 ? sample / args.oldMax : sample / args.oldMin;
}
/**
* Change the bit depth from float to float.
* @param {number} sample The sample.
* @return {number}
* @private
*/
function floatToFloat_(sample) {
f64f32_[0] = sample;
return f64f32_[0];
}
/**
* Change the bit depth from float to float.
* @param {number} sample The sample.
* @return {number}
* @private
*/
function floatToFloat_(sample) {
f64f32_[0] = sample;
return f64f32_[0];
}
/**
* Return the function to change the bit depth of a sample.
* @param {string} original The original bit depth of the data.
* One of "8" ... "53", "32f", "64"
* @param {string} target The new bit depth of the data.
* One of "8" ... "53", "32f", "64"
* @return {!Function}
* @private
*/
function getBitDepthFunction_(original, target) {
/** @type {!Function} */
let func = function(x) {return x;};
if (original != target) {
if (["32f", "64"].includes(original)) {
if (["32f", "64"].includes(target)) {
func = floatToFloat_;
/**
* Return the function to change the bit depth of a sample.
* @param {string} original The original bit depth of the data.
* One of "8" ... "53", "32f", "64"
* @param {string} target The new bit depth of the data.
* One of "8" ... "53", "32f", "64"
* @return {!Function}
* @private
*/
function getBitDepthFunction_(original, target) {
/** @type {!Function} */
let func = function(x) {return x;};
if (original != target) {
if (["32f", "64"].includes(original)) {
if (["32f", "64"].includes(target)) {
func = floatToFloat_;
} else {
func = floatToInt_;
}
} else {
func = floatToInt_;
if (["32f", "64"].includes(target)) {
func = intToFloat_;
} else {
func = intToInt_;
}
}
} else {
if (["32f", "64"].includes(target)) {
func = intToFloat_;
} else {
func = intToInt_;
}
}
return func;
}
return func;
}
/**
* Validate the bit depth.
* @param {string} bitDepth The original bit depth.
* Should be one of "8" ... "53", "32f" or "64".
* @throws {Error} If any argument does not meet the criteria.
* @private
*/
function validateBitDepth_(bitDepth) {
if ((bitDepth != "32f" && bitDepth != "64") &&
(parseInt(bitDepth, 10) < "8" || parseInt(bitDepth, 10) > "53")) {
throw new Error("Invalid bit depth.");
/**
* Validate the bit depth.
* @param {string} bitDepth The original bit depth.
* Should be one of "8" ... "53", "32f" or "64".
* @throws {Error} If any argument does not meet the criteria.
* @private
*/
function validateBitDepth_(bitDepth) {
if ((bitDepth != "32f" && bitDepth != "64") &&
(parseInt(bitDepth, 10) < "8" || parseInt(bitDepth, 10) > "53")) {
throw new Error("Invalid bit depth.");
}
}
}
return bitdepth;
/***/ })
/******/ ]);
});
})));

@@ -47,3 +47,3 @@ /*

*/
export function bitdepth(samples, original, target, outputArray) {
export default function bitdepth(samples, original, target, outputArray) {
validateBitDepth_(original);

@@ -50,0 +50,0 @@ validateBitDepth_(target);

{
"name": "bitdepth",
"version": "5.0.0",
"version": "6.0.0",
"description": "Change the resolution of samples to and from any bit depth.",

@@ -10,2 +10,3 @@ "homepage": "https://github.com/rochars/bitdepth",

"module": "./index.js",
"es2015": "./dist/bitdepth.js",
"browser": "./dist/bitdepth.umd.js",

@@ -40,10 +41,14 @@ "jsdelivr": "./dist/bitdepth.min.js",

},
"directories": {
"dist": "./dist"
},
"scripts": {
"lint": "jshint index.js && jshint test",
"test": "nyc --require=esm ./node_modules/mocha/bin/_mocha test --recursive -R min",
"test-min": "node ./node_modules/mocha/bin/_mocha test --min --recursive -R min",
"test-cjs": "node ./node_modules/mocha/bin/_mocha test --cjs --recursive -R min",
"test-umd": "node ./node_modules/mocha/bin/_mocha test --umd --recursive -R min",
"test-dist": "npm run test-min && npm run test-cjs && npm run test-umd",
"pack": "webpack && npm run test-dist && npm run test",
"test": "nyc --require=esm ./node_modules/mocha/bin/_mocha test --recursive -R dot",
"test-min": "node ./node_modules/mocha/bin/_mocha test --min --recursive -R dot",
"test-cjs": "node ./node_modules/mocha/bin/_mocha test --cjs --recursive -R dot",
"test-umd": "node ./node_modules/mocha/bin/_mocha test --umd --recursive -R dot",
"test-esm": "nyc ./node_modules/mocha/bin/_mocha test --esm --require=esm --recursive -R dot",
"test-dist": "npm run test-min && npm run test-cjs && npm run test-umd && npm run test-esm",
"pack": "rollup --config && webpack && npm run test-dist && npm run test",
"doc": "./node_modules/.bin/jsdoc index.js -d docs -r README.md -t node_modules/docdash",

@@ -65,4 +70,8 @@ "build": "npm run lint && npm run pack && npm run doc",

"nyc": "^12.0.2",
"webpack": "^3.12.0"
"rollup": "^0.61.2",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-node-resolve": "^3.3.0",
"webpack": "^4.12.1",
"webpack-cli": "^3.0.8"
}
}

@@ -8,4 +8,7 @@ # bitdepth

## About
Change the resolution of samples to and from any bit depth.
Change the resolution of samples. Supported bit depths (to and from):
- "8": 8-bit int (unsigned)
- Anything between "9" and "53" (integers, signed)
- "32f": 32-bit float
- "64": 64-bit float

@@ -17,2 +20,24 @@ ## Install

## Use
### ES6
import bitdepth from **bitdepth.js**:
```javascript
import bitdepth from 'bitdepth.js';
// 8 bit samples
let samples = [0, 255]
// Make'em 32-bit floating point
// The input array is modified in place.
bitdepth(samples, "8", "32f");
```
### Node
```javascript
const bitdepth = require("bitdepth");
let samples = [0, 255]
bitdepth(samples, "8", "32f");
```
## Browser

@@ -22,2 +47,6 @@ Use the compiled file in the */dist* folder:

<script src="bitdepth.min.js"></script>
<script>
var samples = [0, 255]
bitdepth(samples, "8", "32f");
</script>
```

@@ -27,3 +56,3 @@

```html
<script src="https://cdn.jsdelivr.net/npm/bitdepth@5"></script>
<script src="https://cdn.jsdelivr.net/npm/bitdepth@6"></script>
```

@@ -33,21 +62,11 @@

```html
<script src="https://unpkg.com/bitdepth@5"></script>
<script src="https://unpkg.com/bitdepth@6"></script>
```
## Use
Supported bit depths (to and from):
- "8": 8-bit int (unsigned)
- Anything between "9" and "53" (integers, signed)
- "32f": 32-bit float
- "64": 64-bit float
```javascript
const bitdepth = require("bitdepth").bitdepth;
// 8 bit samples
let samples = [0, 255]
// Make'em 32-bit floating point
// The input array is modified in place.
bitdepth(samples, "8", "32f");
Or as a ES6 module in modern browsers from [jspm](https://jspm.io):
```html
<script type="module">
import bitdepth from 'https://dev.jspm.io/bitdepth';
// ...
</script>
```

@@ -73,22 +92,10 @@

## Distribution
This library is implemented as a ES6 module and also distributed as a CommonJS module, UMD module and a compiled script for browsers. If your system does not pick one automatically for you, you can pick one in the **dist/** folder.
- The CommonJS is the one used by Node. It is served in the "main" field of this library's package.json
- The UMD module is compatible with Node, AMD and browsers. It is served in the "browser" field.
- The compiled dist is browser-only and should be the one served by CDNs.
- The "module" field points to "./index.js" and should be the default entry point.
This library is a ES6 module also distributed as a CommonJS module, UMD and a compiled script for browsers.
If you are using a module bundler to compile a module that depends on this library you might need to specify what is the correct entry point as some bundlers will assume "browser". In general, you should point to "module".
- The **CommonJS** is the one used by Node. It is served in the "main" field of package.json
- The **UMD** module is compatible with Node, AMD and browsers. It is served in the "browser" field.
- The **compiled dist** is browser-only and should be the one served by CDNs.
- The **ES6** dist is **bitdepth.js**, served as "module" in package.json
### webpack example:
```javascript
module.exports = {
entry: './index.js',
resolve: {
// tells webpack to use 'module' or 'main'
// not 'browser'
mainFields: ['module', 'main']
},
...
};
```
You may load both **bitdepth.umd.js** and **bitdepth.min.js** in the browser with ```<script>``` tags.

@@ -95,0 +102,0 @@ ## LICENSE

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