Socket
Socket
Sign inDemoInstall

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 6.0.0 to 7.0.0-alpha.1

externs.js

3

CHANGELOG.md
# CHANGELOG
## v7.0.0 (2018-07-02)
- Write to and from typed arrays
## v6.0.0 (2018-06-25)

@@ -4,0 +7,0 @@ - Allow better use of this lib as a dependency:

21

dist/bitdepth.cjs.js

@@ -40,4 +40,4 @@ 'use strict';

/**
* Change the bit depth of samples. The input array is modified in-place.
* @param {!Array<number>} samples The samples.
* Change the bit depth of samples. The input array.
* @param {!TypedArray} input The samples.
* @param {string} original The original bit depth of the data.

@@ -47,9 +47,7 @@ * One of "8" ... "53", "32f", "64"

* One of "8" ... "53", "32f", "64"
* @param {Array<number>=} outputArray An optional array to write
converted samples to. Useful for writing to typed arrays.
* @param {!TypedArray} output The output array.
*/
function bitdepth(samples, original, target, outputArray) {
function bitDepth(input, original, target, output) {
validateBitDepth_(original);
validateBitDepth_(target);
outputArray = outputArray || samples;
/** @type {!Function} */

@@ -65,7 +63,7 @@ let toFunction = getBitDepthFunction_(original, target);

/** @type {number} */
const len = samples.length;
const len = input.length;
// sign the samples if original is 8-bit
if (original == "8") {
for (let i=0; i<len; i++) {
outputArray[i] = samples[i] -= 128;
output[i] = input[i] -= 128;
}

@@ -75,3 +73,3 @@ }

for (let i=0; i<len; i++) {
outputArray[i] = toFunction(samples[i], options);
output[i] = toFunction(input[i], options);
}

@@ -81,3 +79,3 @@ // unsign the samples if target is 8-bit

for (let i=0; i<len; i++) {
outputArray[i] = outputArray[i] += 128;
output[i] = output[i] += 128;
}

@@ -181,2 +179,3 @@ }

module.exports = bitdepth;
module.exports = bitDepth;
module.exports.default = bitDepth;

@@ -38,4 +38,4 @@ /*

/**
* Change the bit depth of samples. The input array is modified in-place.
* @param {!Array<number>} samples The samples.
* Change the bit depth of samples. The input array.
* @param {!TypedArray} input The samples.
* @param {string} original The original bit depth of the data.

@@ -45,9 +45,7 @@ * One of "8" ... "53", "32f", "64"

* One of "8" ... "53", "32f", "64"
* @param {Array<number>=} outputArray An optional array to write
converted samples to. Useful for writing to typed arrays.
* @param {!TypedArray} output The output array.
*/
function bitdepth(samples, original, target, outputArray) {
function bitDepth(input, original, target, output) {
validateBitDepth_(original);
validateBitDepth_(target);
outputArray = outputArray || samples;
/** @type {!Function} */

@@ -63,7 +61,7 @@ let toFunction = getBitDepthFunction_(original, target);

/** @type {number} */
const len = samples.length;
const len = input.length;
// sign the samples if original is 8-bit
if (original == "8") {
for (let i=0; i<len; i++) {
outputArray[i] = samples[i] -= 128;
output[i] = input[i] -= 128;
}

@@ -73,3 +71,3 @@ }

for (let i=0; i<len; i++) {
outputArray[i] = toFunction(samples[i], options);
output[i] = toFunction(input[i], options);
}

@@ -79,3 +77,3 @@ // unsign the samples if target is 8-bit

for (let i=0; i<len; i++) {
outputArray[i] = outputArray[i] += 128;
output[i] = output[i] += 128;
}

@@ -179,2 +177,2 @@ }

export default bitdepth;
export default bitDepth;

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

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;
/*
bitdepth Copyright (c) 2017-2018 Rafael da Silva Rocha.
*/
var l="function"==typeof Object.defineProperties?Object.defineProperty:function(a,f,d){a!=Array.prototype&&a!=Object.prototype&&(a[f]=d.value)},n="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function p(a,f){if(f){var d=n;a=a.split(".");for(var e=0;e<a.length-1;e++){var h=a[e];h in d||(d[h]={});d=d[h]}a=a[a.length-1];e=d[a];f=f(e);f!=e&&null!=f&&l(d,a,{configurable:!0,writable:!0,value:f})}}
p("Object.is",function(a){return a?a:function(a,d){return a===d?0!==a||1/a===1/d:a!==a&&d!==d}});p("Array.prototype.includes",function(a){return a?a:function(a,d){var e=this;e instanceof String&&(e=String(e));var f=e.length;d=d||0;for(0>d&&(d=Math.max(d+f,0));d<f;d++){var k=e[d];if(k===a||Object.is(k,a))return!0}return!1}});
window.bitDepth=function(){function a(b,c){return b=0<b?parseInt(b/c.c*c.a,10):parseInt(b/c.f*c.b,10)}function f(b,c){return parseInt(0<b?b*c.a:b*c.b,10)}function d(b,c){return 0<b?b/c.c:b/c.f}function e(b){m[0]=b;return m[0]}function h(b,c){function g(b){return b}b!=c&&(["32f","64"].includes(b)?["32f","64"].includes(c)?g=e:g=f:g=["32f","64"].includes(c)?d:a);return g}function k(b){if("32f"!=b&&"64"!=b&&("8">parseInt(b,10)||"53"<parseInt(b,10)))throw Error("Invalid bit depth.");}var m=new Float32Array(1);
return function(b,c,a,d){k(c);k(a);var e=h(c,a),f={f:Math.pow(2,parseInt(c,10))/2,b:Math.pow(2,parseInt(a,10))/2,c:Math.pow(2,parseInt(c,10))/2-1,a:Math.pow(2,parseInt(a,10))/2-1},g=b.length;if("8"==c)for(c=0;c<g;c++)d[c]=b[c]-=128;for(c=0;c<g;c++)d[c]=e(b[c],f);if("8"==a)for(b=0;b<g;b++)d[b]=d[b]+=128}}();
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.bitdepth = factory());
(global.bitDepth = factory());
}(this, (function () { 'use strict';

@@ -44,4 +44,4 @@

/**
* Change the bit depth of samples. The input array is modified in-place.
* @param {!Array<number>} samples The samples.
* Change the bit depth of samples. The input array.
* @param {!TypedArray} input The samples.
* @param {string} original The original bit depth of the data.

@@ -51,9 +51,7 @@ * One of "8" ... "53", "32f", "64"

* One of "8" ... "53", "32f", "64"
* @param {Array<number>=} outputArray An optional array to write
converted samples to. Useful for writing to typed arrays.
* @param {!TypedArray} output The output array.
*/
function bitdepth(samples, original, target, outputArray) {
function bitDepth(input, original, target, output) {
validateBitDepth_(original);
validateBitDepth_(target);
outputArray = outputArray || samples;
/** @type {!Function} */

@@ -69,7 +67,7 @@ let toFunction = getBitDepthFunction_(original, target);

/** @type {number} */
const len = samples.length;
const len = input.length;
// sign the samples if original is 8-bit
if (original == "8") {
for (let i=0; i<len; i++) {
outputArray[i] = samples[i] -= 128;
output[i] = input[i] -= 128;
}

@@ -79,3 +77,3 @@ }

for (let i=0; i<len; i++) {
outputArray[i] = toFunction(samples[i], options);
output[i] = toFunction(input[i], options);
}

@@ -85,3 +83,3 @@ // unsign the samples if target is 8-bit

for (let i=0; i<len; i++) {
outputArray[i] = outputArray[i] += 128;
output[i] = output[i] += 128;
}

@@ -185,4 +183,4 @@ }

return bitdepth;
return bitDepth;
})));
# Distribution
This library is a ES6 module also distributed as a CommonJS module, UMD module and a compiled script for browsers. It works out of the box in Node when installed with ```npm install bitdepth```.
This library is a ES6 module also distributed as a CommonJS module, UMD and a compiled script for browsers.
## If you are using this lib in a browser:
- 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
You may load both **bitdepth.umd.js** and **bitdepth.min.js** in the browser with ```<script>``` tags. Ideally you should use **bitdepth.min.js**. You can load it via the https://unpkg.com and https://www.jsdelivr.com/ CDNs:
You may load both **bitdepth.umd.js** and **bitdepth.min.js** in the browser with ```<script>``` tags.
[unpkg](https://www.unpkg.com):
```html
<script src="https://unpkg.com/bitdepth"></script>
```
[jsDelivr](https://www.jsdelivr.com):
```html
<script src="https://cdn.jsdelivr.net/npm/bitdepth"></script>
```
## If you are using this lib as a dependency:
- The **CommonJS** is the dist file used by Node. It is served in the "main" field of package.json. It includes all the sources but no dependencies. Dependencies will be imported from the **node_modules** folder. This is the source you are running when you **npm install bitdepth**.
- The **UMD** module is compatible with Node, AMD and browsers. It is served in the "browser" field of package.json. It includes all dependencies. This file is not compiled/minified as it may be used by module bundlers. Compilation/minification should be up to the bundler consuming this file.
- The **compiled dist** is browser-only and should be the one served by CDNs. It includes all the dependencies. It is used in the "unpkg" and "jsdelivr" fields of package.json.
- The **ES6 dist** is **bitdepth.js**, served as "es2015" in package.json. It includes all the dependencies. It is not compiled/minified.
- **./index.js** is served as "module" in package.json. It should be used by systems that support ES modules and are aware of Node's module path resolution (a module bundler, for instance). This should be the entry point for bundlers in most cases - this will avoid code duplication in the case of shared dependencies (as opposed to using "browser" as the entry point).
If your module bundler is using "browser" as the entry point **your dist should work the same** but will be a larger file.
## LICENSE
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.

@@ -38,4 +38,4 @@ /*

/**
* Change the bit depth of samples. The input array is modified in-place.
* @param {!Array<number>} samples The samples.
* Change the bit depth of samples. The input array.
* @param {!TypedArray} input The samples.
* @param {string} original The original bit depth of the data.

@@ -45,9 +45,7 @@ * One of "8" ... "53", "32f", "64"

* One of "8" ... "53", "32f", "64"
* @param {Array<number>=} outputArray An optional array to write
converted samples to. Useful for writing to typed arrays.
* @param {!TypedArray} output The output array.
*/
export default function bitdepth(samples, original, target, outputArray) {
export default function bitDepth(input, original, target, output) {
validateBitDepth_(original);
validateBitDepth_(target);
outputArray = outputArray || samples;
/** @type {!Function} */

@@ -63,7 +61,7 @@ let toFunction = getBitDepthFunction_(original, target);

/** @type {number} */
const len = samples.length;
const len = input.length;
// sign the samples if original is 8-bit
if (original == "8") {
for (let i=0; i<len; i++) {
outputArray[i] = samples[i] -= 128;
output[i] = input[i] -= 128;
}

@@ -73,3 +71,3 @@ }

for (let i=0; i<len; i++) {
outputArray[i] = toFunction(samples[i], options);
output[i] = toFunction(input[i], options);
}

@@ -79,3 +77,3 @@ // unsign the samples if target is 8-bit

for (let i=0; i<len; i++) {
outputArray[i] = outputArray[i] += 128;
output[i] = output[i] += 128;
}

@@ -82,0 +80,0 @@ }

{
"name": "bitdepth",
"version": "6.0.0",
"description": "Change the resolution of samples to and from any bit depth.",
"version": "7.0.0-alpha.1",
"description": "Change the resolution of samples.",
"homepage": "https://github.com/rochars/bitdepth",

@@ -14,2 +14,3 @@ "author": "Rafael S. Rocha <rocha.rafaelsilva@gmail.com>",

"unpkg": "./dist/bitdepth.min.js",
"types": "./index.d.ts",
"engines": {

@@ -52,3 +53,3 @@ "node": ">=8"

"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",
"pack": "rollup --config && npm run test-dist && npm run test",
"doc": "./node_modules/.bin/jsdoc index.js -d docs -r README.md -t node_modules/docdash",

@@ -71,7 +72,6 @@ "build": "npm run lint && npm run pack && npm run doc",

"rollup": "^0.61.2",
"rollup-plugin-closure-compiler-js": "^1.0.6",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-node-resolve": "^3.3.0",
"webpack": "^4.12.1",
"webpack-cli": "^3.0.8"
"rollup-plugin-node-resolve": "^3.3.0"
}
}

@@ -22,12 +22,5 @@ # bitdepth

### ES6
import bitdepth from **bitdepth.js**:
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");
import bitDepth from 'bitdepth.js';
```

@@ -37,5 +30,3 @@

```javascript
const bitdepth = require("bitdepth");
let samples = [0, 255]
bitdepth(samples, "8", "32f");
const bitDepth = require("bitdepth");
```

@@ -47,6 +38,2 @@

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

@@ -56,3 +43,3 @@

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

@@ -62,3 +49,3 @@

```html
<script src="https://unpkg.com/bitdepth@6"></script>
<script src="https://unpkg.com/bitdepth"></script>
```

@@ -69,3 +56,3 @@

<script type="module">
import bitdepth from 'https://dev.jspm.io/bitdepth';
import bitDepth from 'https://dev.jspm.io/bitdepth';
// ...

@@ -76,8 +63,6 @@ </script>

## API
### bitdepth()
```javascript
/**
* Change the bit depth of samples. The input array is modified in-place.
* @param {!Array<number>} samples The samples.
* Change the bit depth of samples. The input array.
* @param {!TypedArray} input The samples.
* @param {string} original The original bit depth of the data.

@@ -87,18 +72,7 @@ * One of "8" ... "53", "32f", "64"

* One of "8" ... "53", "32f", "64"
* @param {Array<number>=} outputArray An optional array to write
converted samples to. Useful for writing to typed arrays.
* @param {!TypedArray} output The output array.
*/
function bitdepth(samples, original, target, outputArray) {}
function bitDepth(input, original, target, output) {}
```
## Distribution
This library is a ES6 module also distributed as a CommonJS module, UMD and a compiled script for browsers.
- 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
You may load both **bitdepth.umd.js** and **bitdepth.min.js** in the browser with ```<script>``` tags.
## LICENSE

@@ -105,0 +79,0 @@ Copyright (c) 2017-2018 Rafael da Silva Rocha.

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