Socket
Socket
Sign inDemoInstall

js-crc

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-crc - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

.npmignore

4

bower.json
{
"name": "js-crc",
"version": "0.1.0",
"main": ["build/crc.min.js"],
"version": "0.2.0",
"main": ["src/crc.js"],
"ignore": [

@@ -6,0 +6,0 @@ "samples",

@@ -1,12 +0,10 @@

/*
* js-crc v0.1.0
* https://github.com/emn178/js-crc
/**
* [js-crc]{@link https://github.com/emn178/js-crc}
*
* Copyright 2015, emn178@gmail.com
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
* @namespace crc
* @version 0.2.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2017
* @license MIT
*/
(function(m,t){var r="undefined"!=typeof module;r&&(m=global);var g="0123456789abcdef".split(""),n=[{name:"crc32",polynom:3988292384,initValue:-1,bytes:4},{name:"crc16",polynom:40961,initValue:0,bytes:2}],c,l,p,k;for(c=0;c<n.length;++c){var e=n[c];e.method=function(c){return function(a){var d=a,b="string"!=typeof d;b&&d.constructor==ArrayBuffer&&(d=new Uint8Array(d));a=c.initValue;var f,e=d.length,h=c.table;if(b)for(f=0;f<e;++f)a=h[(a^d[f])&255]^a>>>8;else for(f=0;f<e;++f)b=d.charCodeAt(f),128>b?
a=h[(a^b)&255]^a>>>8:(2048>b?a=h[(a^(192|b>>6))&255]^a>>>8:(55296>b||57344<=b?a=h[(a^(224|b>>12))&255]^a>>>8:(b=65536+((b&1023)<<10|d.charCodeAt(++f)&1023),a=h[(a^(240|b>>18))&255]^a>>>8,a=h[(a^(128|b>>12&63))&255]^a>>>8),a=h[(a^(128|b>>6&63))&255]^a>>>8),a=h[(a^(128|b&63))&255]^a>>>8);a^=c.initValue;d="";2<c.bytes&&(d+=g[a>>28&15]+g[a>>24&15]+g[a>>20&15]+g[a>>16&15]);return d+=g[a>>12&15]+g[a>>8&15]+g[a>>4&15]+g[a&15]}}(e);e.table=[];for(l=0;256>l;++l){k=l;for(p=0;8>p;++p)k=k&1?e.polynom^k>>>1:k>>>
1;e.table[l]=k>>>0}}var q;!m.HI_CRC32_TEST&&r?q=module.exports={}:m&&(q=m);for(c=0;c<n.length;++c)e=n[c],q[e.name]=e.method})(this);
!function(){"use strict";var e="object"==typeof window?window:{},o=!e.JS_CRC_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;o&&(e=global);var n,t,r,f,a=!e.JS_CRC_NO_COMMON_JS&&"object"==typeof module&&module.exports,i="function"==typeof define&&define.amd,l=!e.JS_CRC_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,s="0123456789abcdef".split(""),c=[{name:"crc32",polynom:3988292384,initValue:-1,bytes:4},{name:"crc16",polynom:40961,initValue:0,bytes:2}];for(n=0;n<c.length;++n){var u=c[n];for(u.method=function(e){return function(o){return d(o,e)}}(u),u.table=[],t=0;256>t;++t){for(f=t,r=0;8>r;++r)f=1&f?u.polynom^f>>>1:f>>>1;u.table[t]=f>>>0}}var d=function(e,o){var n="string"!=typeof e;n&&l&&e instanceof ArrayBuffer&&(e=new Uint8Array(e));var t,r,f=o.initValue,a=e.length,i=o.table;if(n)for(r=0;a>r;++r)f=i[255&(f^e[r])]^f>>>8;else for(r=0;a>r;++r)t=e.charCodeAt(r),128>t?f=i[255&(f^t)]^f>>>8:2048>t?(f=i[255&(f^(192|t>>6))]^f>>>8,f=i[255&(f^(128|63&t))]^f>>>8):55296>t||t>=57344?(f=i[255&(f^(224|t>>12))]^f>>>8,f=i[255&(f^(128|t>>6&63))]^f>>>8,f=i[255&(f^(128|63&t))]^f>>>8):(t=65536+((1023&t)<<10|1023&e.charCodeAt(++r)),f=i[255&(f^(240|t>>18))]^f>>>8,f=i[255&(f^(128|t>>12&63))]^f>>>8,f=i[255&(f^(128|t>>6&63))]^f>>>8,f=i[255&(f^(128|63&t))]^f>>>8);f^=o.initValue;var c="";return o.bytes>2&&(c+=s[f>>28&15]+s[f>>24&15]+s[f>>20&15]+s[f>>16&15]),c+=s[f>>12&15]+s[f>>8&15]+s[f>>4&15]+s[15&f]},p={};for(n=0;n<c.length;++n){var u=c[n];p[u.name]=u.method}if(a)module.exports=p;else{for(n=0;n<c.length;++n){var u=c[n];e[u.name]=u.method}i&&define(function(){return p})}}();

@@ -1,3 +0,12 @@

# v0.1.0 / 2015-03-08
# Change Log
Create project
## v0.2.0 / 2017-02-08
### Added
- AMD support.
### Fixed
- `root` is undefined in some special environment.
## v0.1.0 / 2015-03-08
### Added
- create project.

@@ -1,2 +0,2 @@

Copyright 2015 emn178@gmail.com
Copyright 2015-2017 Chen, Yi-Cyuan

@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining

{
"name": "js-crc",
"version": "0.1.0",
"version": "0.2.0",
"description": "Simple CRC checksum functions for JavaScript(CRC-16 and CRC-32).",

@@ -8,7 +8,11 @@ "main": "src/crc.js",

"expect.js": "~0.3.1",
"jscoverage": "~0.5.9"
"jscoverage": "~0.5.9",
"mocha": "~2.3.4",
"uglifyjs": "~2.4.10"
},
"scripts": {
"test": "mocha tests/node-test.js -r jscoverage",
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls"
"report": "mocha tests/node-test.js -r jscoverage --covout=html",
"coveralls": "mocha tests/node-test.js -R mocha-lcov-reporter -r jscoverage | coveralls",
"build": "uglifyjs src/crc.js --compress --mangle --comments --output build/crc.min.js"
},

@@ -25,3 +29,3 @@ "repository": {

"license": "MIT",
"author": "emn178 <emn178@gmail.com>",
"author": "Chen, Yi-Cyuan <emn178@gmail.com>",
"homepage": "https://github.com/emn178/js-crc",

@@ -28,0 +32,0 @@ "bugs": {

@@ -28,29 +28,23 @@ # js-crc

```JavaScript
crc32 = require('js-crc').crc32;
crc16 = require('js-crc').crc16;
var crc32 = require('js-crc').crc32;
var crc16 = require('js-crc').crc16;
```
It supports AMD:
```JavaScript
require(['your/path/crc.js'], function (crc) {
var crc32 = crc.crc32;
var crc16 = crc.crc16;
// ...
});
## Example
Code
```JavaScript
crc32('The quick brown fox jumps over the lazy dog');
crc32('The quick brown fox jumps over the lazy dog.');
```
Output
crc32('The quick brown fox jumps over the lazy dog'); // 414fa339
crc32('The quick brown fox jumps over the lazy dog.'); // 519025e9
414fa339
519025e9
It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` input:
Code
```JavaScript
crc32([0]);
crc32(new Uint8Array([0]));
// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` input:
crc32([0]); // d202ef8d
crc32(new Uint8Array([0])); // d202ef8d
```
Output
d202ef8d
d202ef8d
## License

@@ -61,2 +55,2 @@ The project is released under the [MIT license](http://www.opensource.org/licenses/MIT).

The project's website is located at https://github.com/emn178/js-crc
Author: emn178@gmail.com
Author: Chen, Yi-Cyuan (emn178@gmail.com)

@@ -1,17 +0,22 @@

/*
* js-crc v0.1.0
* https://github.com/emn178/js-crc
/**
* [js-crc]{@link https://github.com/emn178/js-crc}
*
* Copyright 2015, emn178@gmail.com
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
* @namespace crc
* @version 0.2.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2017
* @license MIT
*/
;(function(root, undefined) {
/*jslint bitwise: true */
(function () {
'use strict';
var NODE_JS = typeof(module) != 'undefined';
if(NODE_JS) {
var root = typeof window === 'object' ? window : {};
var NODE_JS = !root.JS_CRC_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
}
var COMMON_JS = !root.JS_CRC_NO_COMMON_JS && typeof module === 'object' && module.exports;
var AMD = typeof define === 'function' && define.amd;
var ARRAY_BUFFER = !root.JS_CRC_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
var HEX_CHARS = '0123456789abcdef'.split('');

@@ -35,6 +40,6 @@

var i, j, k, b;
for(i = 0;i < Modules.length;++i) {
for (i = 0; i < Modules.length; ++i) {
var m = Modules[i];
m.method = (function(m) {
return function(message) {
m.method = (function (m) {
return function (message) {
return crc(message, m);

@@ -44,5 +49,5 @@ };

m.table = [];
for(j = 0;j < 256;++j) {
for (j = 0; j < 256; ++j) {
b = j;
for(k = 0;k < 8;++k) {
for (k = 0; k < 8; ++k) {
b = b & 1 ? m.polynom ^ (b >>> 1) : b >>> 1;

@@ -54,5 +59,5 @@ }

var crc = function(message, module) {
var notString = typeof(message) != 'string';
if(notString && message.constructor == ArrayBuffer) {
var crc = function (message, module) {
var notString = typeof message !== 'string';
if (notString && ARRAY_BUFFER && message instanceof ArrayBuffer) {
message = new Uint8Array(message);

@@ -62,8 +67,8 @@ }

var crc = module.initValue, code, i, length = message.length, table = module.table;
if(notString) {
for(i = 0;i < length;++i) {
if (notString) {
for (i = 0; i < length; ++i) {
crc = table[(crc ^ message[i]) & 0xFF] ^ (crc >>> 8);
}
} else {
for(i = 0;i < length;++i) {
for (i = 0; i < length; ++i) {
code = message.charCodeAt(i);

@@ -91,3 +96,3 @@ if (code < 0x80) {

var hex = '';
if(module.bytes > 2) {
if (module.bytes > 2) {
hex += HEX_CHARS[(crc >> 28) & 0x0F] + HEX_CHARS[(crc >> 24) & 0x0F] +

@@ -101,12 +106,20 @@ HEX_CHARS[(crc >> 20) & 0x0F] + HEX_CHARS[(crc >> 16) & 0x0F];

var exports;
if(!root.HI_CRC32_TEST && NODE_JS) {
exports = module.exports = {};
} else if(root) {
exports = root;
}
for(i = 0;i < Modules.length;++i) {
var exports = {};
for (i = 0;i < Modules.length;++i) {
var m = Modules[i];
exports[m.name] = m.method;
}
}(this));
if (COMMON_JS) {
module.exports = exports;
} else {
for (i = 0;i < Modules.length;++i) {
var m = Modules[i];
root[m.name] = m.method;
}
if (AMD) {
define(function() {
return exports;
});
}
}
})();

@@ -0,13 +1,61 @@

// Node.js env
expect = require('expect.js');
crc32 = require('../src/crc.js').crc32;
crc16 = require('../src/crc.js').crc16;
expect = require('expect.js');
require('./test.js');
delete require.cache[require.resolve('../src/crc.js')]
delete require.cache[require.resolve('./test.js')]
crc32 = null
crc16 = null
delete require.cache[require.resolve('../src/crc.js')];
delete require.cache[require.resolve('./test.js')];
crc32 = null;
crc16 = null;
HI_CRC32_TEST = true;
// Webpack browser env
JS_CRC_NO_NODE_JS = true;
window = global;
crc32 = require('../src/crc.js').crc32;
crc16 = require('../src/crc.js').crc16;
require('./test.js');
delete require.cache[require.resolve('../src/crc.js')];
delete require.cache[require.resolve('./test.js')];
crc32 = null;
crc16 = null;
// browser env
JS_CRC_NO_NODE_JS = true;
JS_CRC_NO_COMMON_JS = true;
window = global;
require('../src/crc.js');
require('./test.js');
delete require.cache[require.resolve('../src/crc.js')];
delete require.cache[require.resolve('./test.js')];
crc32 = null;
crc16 = null;
// browser env and no array buffer
JS_CRC_NO_NODE_JS = true;
JS_CRC_NO_COMMON_JS = true;
JS_CRC_NO_ARRAY_BUFFER = true;
window = global;
require('../src/crc.js');
require('./test.js');
delete require.cache[require.resolve('../src/crc.js')];
delete require.cache[require.resolve('./test.js')];
crc32 = null;
crc16 = null;
// browser AMD
JS_CRC_NO_NODE_JS = true;
JS_CRC_NO_COMMON_JS = true;
JS_CRC_NO_ARRAY_BUFFER = undefined;
window = global;
define = function (func) {
crc16 = func().crc16;
crc32 = func().crc32;
require('./test.js');
};
define.amd = true;
require('../src/crc.js');

@@ -32,7 +32,9 @@ (function(crc32, crc16) {

describe('ArrayBuffer', function() {
it('should be successful', function() {
expect(crc32(new ArrayBuffer(1))).to.be('d202ef8d');
if (typeof JS_CRC_NO_ARRAY_BUFFER === 'undefined') {
describe('ArrayBuffer', function() {
it('should be successful', function() {
expect(crc32(new ArrayBuffer(1))).to.be('d202ef8d');
});
});
});
}
});

@@ -71,9 +73,11 @@ });

describe('ArrayBuffer', function() {
it('should be successful', function() {
expect(crc16(new ArrayBuffer(1))).to.be('0000');
if (typeof JS_CRC_NO_ARRAY_BUFFER === 'undefined') {
describe('ArrayBuffer', function() {
it('should be successful', function() {
expect(crc16(new ArrayBuffer(1))).to.be('0000');
});
});
});
}
});
});
})(crc32, crc16);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc