Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed Require.JS stub in favor of basic window.crc export.

  • Loading branch information...
commit 64ef353275edf3dc0fe1773a16fe9aa923b2defb 1 parent d2bdb13
@alexgorbatchev authored
Showing with 37 additions and 22 deletions.
  1. +9 −4 README.md
  2. +28 −18 lib/crc.js
View
13 README.md
@@ -1,12 +1,12 @@
-# CRC for node.js
+# JavaScript CRC 8, 16 and 32.
-This is a basic port/copy of the JavaScript CRC implementation. The module is compatible with Node.js and Require.js.
+This is a basic port/copy of the JavaScript CRC implementation. The module works with any CommonJS system supporting `module.exports` notation as well as in the browser. When loaded in the browser, all functions end up under the `window.crc` "namespace".
-This is an almost direct copy from http://www.digsys.se/JavaScript/CRC.aspx
+Original code is taken from http://www.digsys.se/JavaScript/CRC.aspx
## Functions
-The following functions are exported:
+The following functions are implemented:
crc8(String) #=> Number
crcArc(String) #=> Number
@@ -19,4 +19,9 @@ The following functions are exported:
## Installation
+ git clone git://github.com/alexgorbatchev/node-crc.git
+
+or
+
npm install crc
+
View
46 lib/crc.js
@@ -1,7 +1,4 @@
-// make this module compatible with RequireJS
-typeof(define) == "undefined" && (define = function(deps, factory) { module.exports = factory.apply(this, deps.map(require)); });
-
-define([], function()
+(function()
{
// CRC-8 in table form
//
@@ -32,7 +29,7 @@ define([], function()
// 'crc' should be initialized to 0x00.
{
return CRC8_TAB[(crc^c)&0xFF];
- }
+ };
// C/C++ language:
//
// inline unsigned char crc8Add(unsigned char crc, unsigned char c)
@@ -75,7 +72,7 @@ define([], function()
// 'crc' should be initialized to 0x0000.
{
return CRC_ARC_TAB[(crc^c)&0xFF]^((crc>>8)&0xFF);
- }
+ };
// C/C++ language:
//
// inline unsigned short crcArcAdd(unsigned short crc, unsigned char c)
@@ -118,7 +115,7 @@ define([], function()
// 'crc' should be initialized to 0x0000.
{
return CRC16_TAB[((crc>>8)^c)&0xFF]^((crc<<8)&0xFFFF);
- }
+ };
// C/C++ language:
//
// inline unsigned short crc16Add(unsigned short crc, unsigned char c)
@@ -165,7 +162,7 @@ define([], function()
// result will always be 0xF0B8 (without the complementation).
{
return FCS_16_TAB[(fcs^c)&0xFF]^((fcs>>8)&0xFF);
- }
+ };
// C/C++ language:
//
@@ -233,7 +230,7 @@ define([], function()
// result will always be 0xDEBB20E3 (without the complementation).
{
return CRC32_TAB[(crc^c)&0xFF]^((crc>>8)&0xFFFFFF);
- }
+ };
//
// C/C++ language:
//
@@ -254,7 +251,7 @@ define([], function()
crc = crc8Add(crc, str.charCodeAt(i));
return crc;
- }
+ };
function crcArc(str)
{
@@ -267,7 +264,7 @@ define([], function()
crc = crcArcAdd(crc, str.charCodeAt(i));
return crc;
- }
+ };
function crc16(str)
{
@@ -280,7 +277,7 @@ define([], function()
crc = crc16Add(crc, str.charCodeAt(i));
return crc;
- }
+ };
function fcs16(str)
{
@@ -293,7 +290,7 @@ define([], function()
fcs = fcs16Add(fcs,str.charCodeAt(i));
return fcs^0xFFFF;
- }
+ };
function crc32(str)
{
@@ -306,7 +303,7 @@ define([], function()
crc = crc32Add(crc, str.charCodeAt(i));
return crc^0xFFFFFFFF;
- }
+ };
/**
* Convert value as 8-bit unsigned integer to 2 digit hexadecimal number.
@@ -321,7 +318,7 @@ define([], function()
str = "0" + str;
return str;
- }
+ };
/**
* Convert value as 16-bit unsigned integer to 4 digit hexadecimal number.
@@ -329,7 +326,7 @@ define([], function()
function hex16(val)
{
return hex8(val >> 8) + hex8(val);
- }
+ };
/**
* Convert value as 32-bit unsigned integer to 8 digit hexadecimal number.
@@ -337,9 +334,22 @@ define([], function()
function hex32(val)
{
return hex16(val >> 16) + hex16(val);
+ };
+
+ var target, property;
+
+ if(typeof(window) == 'undefined')
+ {
+ target = module;
+ property = 'exports';
+ }
+ else
+ {
+ target = window;
+ property = 'crc';
}
- return {
+ target[property] = {
'crc8' : crc8,
'crcArc' : crcArc,
'crc16' : crc16,
@@ -349,4 +359,4 @@ define([], function()
'hex16' : hex16,
'hex32' : hex32
};
-});
+})();

0 comments on commit 64ef353

Please sign in to comment.
Something went wrong with that request. Please try again.