Skip to content

Commit

Permalink
Update version 0.2.0
Browse files Browse the repository at this point in the history
Make it require and nodejs compliant.
  • Loading branch information
tcorral committed Oct 27, 2013
1 parent 0401b7c commit 32f5306
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "JSONC",
"version": "0.0.1",
"version": "0.2.0",
"repository": {
"type": "git",
"url": "git:https://github.com/tcorral/JSONC.git"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "JSONC",
"version": "0.1.0",
"name": "jsoncomp",
"version": "0.2.0",
"description": "Compress your JSON to send and get a lot of data to/from server",
"homepage": "https://tcorral.github.com/JSONC/",
"author": "Tomas Corral",
"main": "./src/Hydra.js",
"main": "./src/JSONC.js",
"keywords": [
"JSON",
"compression"
Expand Down
38 changes: 31 additions & 7 deletions src/JSONC.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
(function(ns)
(function ()
{

var JSONC = {},
var root,
JSONC = {},
isNodeEnvironment,
_nCode = -1,
toString = {}.toString;

/**
* set the correct root depending from the environment.
* @type {Object}
* @private
*/
root = this;
/**
* Check if JSONC is loaded in Node.js environment
* @type {Boolean}
* @private
*/
isNodeEnvironment = typeof exports === 'object' && typeof module === 'object' && typeof module.exports === 'object' && typeof require === 'function';
/**
* Checks if the value exist in the array.
* @param arr
Expand Down Expand Up @@ -295,9 +309,19 @@
return str ? JSON.parse(str): jsonCopy ;
};

/**
* Expose the object to the namespace
* @type {{}}
/*
* Expose Hydra to be used in node.js, as AMD module or as global
*/
ns.JSONC = JSONC;
}((this.Namespace = {})));
root.JSONC = JSONC;
if ( isNodeEnvironment )
{
module.exports = JSONC;
}
else if ( typeof define !== 'undefined' )
{
define( 'jsonc', [], function ()
{
return JSONC;
} );
}
}.call( this ));
20 changes: 10 additions & 10 deletions test/JSONC.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ describe('JSONC API', function ()
{
it('should check that JSONC exist in Namespace', function ()
{
expect( Namespace.JSONC ).not.toBeUndefined();
expect( JSONC ).not.toBeUndefined();
});
it('should check that JSONC has a compress method', function ()
{
expect(typeof Namespace.JSONC.compress === 'function').toBeTruthy();
expect(typeof JSONC.compress === 'function').toBeTruthy();
});
it('should check that JSONC has a decompress method', function ()
{
expect(typeof Namespace.JSONC.decompress === 'function').toBeTruthy();
expect(typeof JSONC.decompress === 'function').toBeTruthy();
});
});
describe('JSONC.compress', function (){
Expand All @@ -24,7 +24,7 @@ describe('JSONC.compress', function (){
}],
retrieved;

retrieved = Namespace.JSONC.compress( original );
retrieved = JSONC.compress( original );

expect(retrieved).toEqual(expected);
});
Expand All @@ -39,7 +39,7 @@ describe('JSONC.compress', function (){
},
retrieved;

retrieved = Namespace.JSONC.compress( original );
retrieved = JSONC.compress( original );

expect(retrieved).toEqual(expected);
});
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('JSONC.compress', function (){
},
retrieved;

retrieved = Namespace.JSONC.compress( original );
retrieved = JSONC.compress( original );

expect(retrieved).toEqual(expected);
});
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('JSONC.compress', function (){
},
retrieved;

retrieved = Namespace.JSONC.compress( original );
retrieved = JSONC.compress( original );

expect(retrieved).toEqual(expected);
});
Expand All @@ -191,7 +191,7 @@ describe('JSONC.decompress', function (){
}],
retrieved;

retrieved = Namespace.JSONC.decompress( original );
retrieved = JSONC.decompress( original );

expect(retrieved).toEqual(expected);
});
Expand All @@ -206,7 +206,7 @@ describe('JSONC.decompress', function (){
},
retrieved;

retrieved = Namespace.JSONC.decompress( original );
retrieved = JSONC.decompress( original );

expect(retrieved).toEqual(expected);
});
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('JSONC.decompress', function (){
},
retrieved;

retrieved = Namespace.JSONC.decompress( original );
retrieved = JSONC.decompress( original );

expect(retrieved).toEqual(expected);
});
Expand Down
38 changes: 31 additions & 7 deletions versions/jsonc.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,27 @@ var LZString = {
}
return result;
}
};;(function(ns)
};;(function ()
{

var JSONC = {},
var root,
JSONC = {},
isNodeEnvironment,
_nCode = -1,
toString = {}.toString;

/**
* set the correct root depending from the environment.
* @type {Object}
* @private
*/
root = this;
/**
* Check if JSONC is loaded in Node.js environment
* @type {Boolean}
* @private
*/
isNodeEnvironment = typeof exports === 'object' && typeof module === 'object' && typeof module.exports === 'object' && typeof require === 'function';
/**
* Checks if the value exist in the array.
* @param arr
Expand Down Expand Up @@ -498,9 +512,19 @@ var LZString = {
return str ? JSON.parse(str): jsonCopy ;
};

/**
* Expose the object to the namespace
* @type {{}}
/*
* Expose Hydra to be used in node.js, as AMD module or as global
*/
ns.JSONC = JSONC;
}((this.Namespace = {})));
root.JSONC = JSONC;
if ( isNodeEnvironment )
{
module.exports = JSONC;
}
else if ( typeof define !== 'undefined' )
{
define( 'jsonc', [], function ()
{
return JSONC;
} );
}
}.call( this ));
4 changes: 2 additions & 2 deletions versions/jsonc.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified versions/jsonc.min.js.gz
Binary file not shown.
Loading

0 comments on commit 32f5306

Please sign in to comment.