couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Klo <jim....@sri.com>
Subject Re: CommonJS syntax help
Date Fri, 05 Oct 2012 17:52:17 GMT
Looks like you assign to your own closure?

Typically what I do for libs that don't support CommonJS is :

(function(exports) {

// insert the lib code


// add exports

exports.jsSHA = jsSHA;

})(exports);


Then:

var shalib = require('lib/sha.js");
var mySHA = new shalib.jsSHA(...);

Sometimes I have to drop the closure and just assign the exports.

- Jim 

Sent from my iPhone

On Oct 5, 2012, at 9:56 AM, "Wordit" <wordituk@gmail.com> wrote:

> On Fri, Oct 5, 2012 at 8:53 AM, Jim Klo <jim.klo@sri.com> wrote:
>> What does jsSHA look like?  Does it export something?  I think CommonJS uses exports
vs export.
> 
> Oops, typo, googd catch. However, it changes nothing. I think the
> problem is related to how jsSHA needs to instantiate a new object
> first. From the docs:
> 
> "Instantiate a new jsSHA object with your string to be hashed and its
> format (HEX or TEXT) as the parameters. Then, call getHash with the
> desired hash variant (SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512)
> and output type (HEX or B64)
> ...
> var shaObj = new jsSHA("This is a Test", "TEXT");
> var hash = shaObj.getHash("SHA-512", "HEX");"
> 
> jsSHA is on Github at:
> 
> https://github.com/Caligatio/jsSHA
> 
> 
> Is it possible that CommonJS does not allow for this kind of module
> usage or is there a workaround?
> 
> Thanks,
> 
> Marcus

Mime
View raw message