diff --git a/Gruntfile.js b/Gruntfile.js index 361a5b0..92e1460 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,5 +1,5 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // @@ -55,16 +55,45 @@ module.exports = function (grunt) { src: ['test/nodifyTest.js'] } }, + pkg: grunt.file.readJSON('package.json'), uglify: { dist: { - files: { - 'dist/enofjs/min.class.js': [ - 'src/ClassFactory.js' - ], - 'dist/enofjs/min.enof.js': [ - 'src/*.js' - ] - } + options: { + banner: '/* !!EnoFJS!! ' + + 'Version: <%= pkg.version %>, ' + + 'Author: <%= pkg.author %>, ' + + 'Fork me on Github: https://github.com/EnoF/EnoFJS */', + mangle: { + except: ['Serializable', 'LinkedHashMap'] + } + }, + files: [ + { + 'dist/enofjs/min.enof.js': [ + 'src/node-shim.js', + 'src/clazz.js', + 'src/*.js' + ] + }, + { + 'dist/enofjs/min.clazz.js': 'src/clazz.js' + }, + { + 'dist/enofjs/min.node-shim.js': 'src/node-shim.js' + }, + { + 'dist/enofjs/min.LinkedHashMap.js': 'src/LinkedHashMap.js' + }, + { + 'dist/enofjs/min.Serializable.js': 'src/Serializable.js' + }, + { + 'dist/enofjs/min.ArrayConverters.js': 'src/ArrayConverters.js' + }, + { + 'dist/enofjs/min.whereIt.js': 'src/whereIt.js' + } + ] } }, version: { diff --git a/bower.json b/bower.json index b8b738d..6047d62 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "enofjs", - "version": "1.3.0", + "version": "2.0.0", "main": "src/enofjs", "devDependencies": { "jasmine": "^2.0" diff --git a/dist/enofjs/min.ArrayConverters.js b/dist/enofjs/min.ArrayConverters.js new file mode 100644 index 0000000..5ff76c6 --- /dev/null +++ b/dist/enofjs/min.ArrayConverters.js @@ -0,0 +1 @@ +/* !!EnoFJS!! Version: 2.0.0, Author: EnoF (http://enof.github.io/EnoFJS, Fork me on Github: https://github.com/EnoF/EnoFJS */!function(){"use strict";function a(){for(var a=this,b=new Uint32Array(a.length/4),c=0;c>>0;return b}function b(a){for(var b=this,c=new Uint8Array(a.buffer),d=0;d (http://enof.github.io/EnoFJS, Fork me on Github: https://github.com/EnoF/EnoFJS */!function(a,b,c){"use strict";var d=a.require("./clazz.js"),e=d(function(){this.private={key:{getSet:null},value:{getSet:null},previous:{getSet:null},next:{getSet:null}},this.constructor=function(a,b){this.private.key=a,this.private.value=b}}),LinkedHashMap=d(function(){this.private={duplicateKeyError:"key already exists in LinkedHashMap",keyNotFoundError:"key not found",size:{get:0},first:{get:null},last:{get:null},hashMap:{},add:function(a,b){if(this.private.hashMap.hasOwnProperty(a))throw new Error(this.private.duplicateKeyError);var c=new e(a,b);return this.private.hashMap[a]=c,this.private.size++,c},remove:function(a){var b=a.getKey();a===this.private.first?(this.private.first=this.private.first.getNext(),this.private.first instanceof e&&this.private.first.setPrevious(null)):a===this.private.last?(this.private.last=this.private.last.getPrevious(),this.private.last.setNext(null)):(a.getPrevious().setNext(a.getNext()),a.getNext().setPrevious(a.getPrevious())),this.private.size--,delete this.private.hashMap[b]}},this.protected={addAfter:function(a,b){var c=a.getNext();null!==c?(c.setPrevious(b),b.setNext(c)):this.private.last=b,a.setNext(b),b.setPrevious(a)},addBefore:function(a,b){var c=a.getPrevious();null!==c?(c.setNext(b),b.setPrevious(c)):this.private.first=b,a.setPrevious(b),b.setNext(a)}},this.public={add:function(a,b){var c=this.private.add(a,b);return 1===this.private.size?this.private.first=c:this.protected.addAfter(this.private.last,c),this.private.last=c,c},addAfter:function(a,b,c){var d=this.private.add(b,c),e=this.public.getById(a);return this.protected.addAfter(e,d),d},addBefore:function(a,b,c){var d=this.private.add(b,c),e=this.public.getById(a);return this.protected.addBefore(e,d),d},addFirst:function(a,b){var c=this.private.add(a,b),d=this.private.first;return null!==d&&this.protected.addBefore(d,c),c},addLast:function(a,b){return this.public.add(a,b)},getById:function(a){var b=this.private.hashMap[a];if(b===c)throw new Error(this.private.keyNotFoundError);return b},isEmpty:function(){return 0===this.private.size},remove:function(a){return this.private.hashMap.hasOwnProperty(a)?this.private.remove(this.public.getById(a)):!1},removeFirst:function(){return null===this.private.first?!1:this.private.remove(this.private.first)},removeLast:function(){return null===this.private.last?!1:this.private.remove(this.private.last)}},this.constructor=function(){this.private.hashMap={}}});a.exports(b,LinkedHashMap,"./LinkedHashMap.js")}(require("./node-shim.js"),module); \ No newline at end of file diff --git a/dist/enofjs/min.Serializable.js b/dist/enofjs/min.Serializable.js new file mode 100644 index 0000000..33bdeb0 --- /dev/null +++ b/dist/enofjs/min.Serializable.js @@ -0,0 +1 @@ +/* !!EnoFJS!! Version: 2.0.0, Author: EnoF (http://enof.github.io/EnoFJS, Fork me on Github: https://github.com/EnoF/EnoFJS */!function(a,b){"use strict";function Serializable(){this.private={deserialize:function(a){for(var b in a)b in this.protected?this.protected[b]=a[b]:b in this.private&&(this.private[b]=a[b])},serialize:function(a,b){for(var c in a){var d=a[c];this.private.isNumberOrString(d)?b[c]=a[c]:d instanceof Array&&(b[c]=[],this.private.serializeArray(d,b[c]),0===b[c].length&&delete b[c])}},isNumberOrString:function(a){var b=typeof a;return"number"===b||"string"===b},serializeArray:function(a,b){for(var c=0;c (http://enof.github.io/EnoFJS, Fork me on Github: https://github.com/EnoF/EnoFJS */!function(a,b,c){"use strict";function d(a){var b=a.extractFunctionName();return e(b,a)}function e(a,b){var d,e,j=q(new b);i("private",j.private,j.public),i("protected",j.protected,j.public),j.extend!==c&&(d=u[j.extend],e=f(j,d));var k=g(j,d);return j.extend!==c&&h(k,e),u[a]=k,o(a,k)}function f(a,b){var c={"private":new b.Private,"protected":new b.Protected,"public":new b.Public,constructor:b.constructor};return m(c.private,a.private),m(c.protected,a.protected),m(c.public,a.public),c}function g(a,b){function d(){}function e(){}function f(){}d.prototype=a.private,e.prototype=a.protected,f.prototype=a.public;var g={extend:a.extend,constructor:a.constructor,"super":b!==c?b.constructor:function(){},Private:d,Protected:e,Public:f};return g}function h(a,b){a.Private.prototype.super=b.private,a.Protected.prototype.super=b.protected,a.Public.prototype.super=b.public,p(a,a.Private.prototype.super),p(a,a.Private.prototype.super),p(a,a.Public.prototype.super)}function i(a,b,c){for(var d in b){var e=b[d],f=!1,g=!1,h=d.capitaliseFirstLetter();e instanceof Object&&(r(e)?(b[d]=e.get,c["get"+h]=j(a,d),f=!0):t(e)&&(b[d]=e.is,c["is"+h]=k(a,d),g=!0),s(e)&&(b[d]=f?e.getSet:g?e.isSet:e.set,c["set"+h]=l(a,d)))}}function j(a,b){return function(){return this[a][b]}}function k(a,b){return function(){return this[a][b]}}function l(a,b){return function(c){this[a][b]=c}}function m(a,b){for(var c in a)b.hasOwnProperty(c)||(b[c]=a[c])}function n(a,b){for(var c in b)a[c]=b[c]}function o(a,b){function d(){var a={"private":new b.Private,"protected":new b.Protected,"public":new b.Public,constructor:b.constructor,"super":b.super};p(a,a.private),p(a,a.protected),p(a,a.public),n(this,a.public),a.constructor.apply(a,arguments)}return b.extend!==c&&(d.prototype=new v[b.extend]),v[a]=d,d}function p(a,b){b.private=a.private||a.Private.prototype,b.protected=a.protected||a.Protected.prototype,b.public=a.public||a.Public.prototype}function q(a){return a.private=a.private||{},a.protected=a.protected||{},a.public=a.public||{},a.super=a.super||{},a.constructor=a.constructor||function(){},a}function r(a){return a.hasOwnProperty("get")||a.hasOwnProperty("getSet")}function s(a){return a.hasOwnProperty("set")||a.hasOwnProperty("getSet")||a.hasOwnProperty("isSet")}function t(a){return a.hasOwnProperty("is")||a.hasOwnProperty("isSet")}var u={},v={};Function.prototype.extractFunctionName=function(){var a=this.toString();return a=a.substr("function ".length),a=a.substr(0,a.indexOf("("))},Function.prototype.bindScope=function(a){var b=this;return function(){return b.apply(a,arguments)}},String.prototype.capitaliseFirstLetter=function(){return this.charAt(0).toUpperCase()+this.slice(1)},a.exports(b,d,"./clazz.js")}(require("./node-shim.js"),module); \ No newline at end of file diff --git a/dist/enofjs/min.enof.js b/dist/enofjs/min.enof.js new file mode 100644 index 0000000..e1afc32 --- /dev/null +++ b/dist/enofjs/min.enof.js @@ -0,0 +1 @@ +/* !!EnoFJS!! Version: 2.0.0, Author: EnoF (http://enof.github.io/EnoFJS, Fork me on Github: https://github.com/EnoF/EnoFJS */!function(a){"use strict";void 0!==a?(a.module={},a.require=function(b){return a.module[b]||a},a.exports=function(b,c,d){a.module[d]=c}):module.exports={require:require,exports:function(a,b){a.exports=b}}}(this.window),function(a,b,c){"use strict";function d(a){var b=a.extractFunctionName();return e(b,a)}function e(a,b){var d,e,j=q(new b);i("private",j.private,j.public),i("protected",j.protected,j.public),j.extend!==c&&(d=u[j.extend],e=f(j,d));var k=g(j,d);return j.extend!==c&&h(k,e),u[a]=k,o(a,k)}function f(a,b){var c={"private":new b.Private,"protected":new b.Protected,"public":new b.Public,constructor:b.constructor};return m(c.private,a.private),m(c.protected,a.protected),m(c.public,a.public),c}function g(a,b){function d(){}function e(){}function f(){}d.prototype=a.private,e.prototype=a.protected,f.prototype=a.public;var g={extend:a.extend,constructor:a.constructor,"super":b!==c?b.constructor:function(){},Private:d,Protected:e,Public:f};return g}function h(a,b){a.Private.prototype.super=b.private,a.Protected.prototype.super=b.protected,a.Public.prototype.super=b.public,p(a,a.Private.prototype.super),p(a,a.Private.prototype.super),p(a,a.Public.prototype.super)}function i(a,b,c){for(var d in b){var e=b[d],f=!1,g=!1,h=d.capitaliseFirstLetter();e instanceof Object&&(r(e)?(b[d]=e.get,c["get"+h]=j(a,d),f=!0):t(e)&&(b[d]=e.is,c["is"+h]=k(a,d),g=!0),s(e)&&(b[d]=f?e.getSet:g?e.isSet:e.set,c["set"+h]=l(a,d)))}}function j(a,b){return function(){return this[a][b]}}function k(a,b){return function(){return this[a][b]}}function l(a,b){return function(c){this[a][b]=c}}function m(a,b){for(var c in a)b.hasOwnProperty(c)||(b[c]=a[c])}function n(a,b){for(var c in b)a[c]=b[c]}function o(a,b){function d(){var a={"private":new b.Private,"protected":new b.Protected,"public":new b.Public,constructor:b.constructor,"super":b.super};p(a,a.private),p(a,a.protected),p(a,a.public),n(this,a.public),a.constructor.apply(a,arguments)}return b.extend!==c&&(d.prototype=new v[b.extend]),v[a]=d,d}function p(a,b){b.private=a.private||a.Private.prototype,b.protected=a.protected||a.Protected.prototype,b.public=a.public||a.Public.prototype}function q(a){return a.private=a.private||{},a.protected=a.protected||{},a.public=a.public||{},a.super=a.super||{},a.constructor=a.constructor||function(){},a}function r(a){return a.hasOwnProperty("get")||a.hasOwnProperty("getSet")}function s(a){return a.hasOwnProperty("set")||a.hasOwnProperty("getSet")||a.hasOwnProperty("isSet")}function t(a){return a.hasOwnProperty("is")||a.hasOwnProperty("isSet")}var u={},v={};Function.prototype.extractFunctionName=function(){var a=this.toString();return a=a.substr("function ".length),a=a.substr(0,a.indexOf("("))},Function.prototype.bindScope=function(a){var b=this;return function(){return b.apply(a,arguments)}},String.prototype.capitaliseFirstLetter=function(){return this.charAt(0).toUpperCase()+this.slice(1)},a.exports(b,d,"./clazz.js")}(require("./node-shim.js"),module),function(){"use strict";function a(){for(var a=this,b=new Uint32Array(a.length/4),c=0;c>>0;return b}function b(a){for(var b=this,c=new Uint8Array(a.buffer),d=0;d (http://enof.github.io/EnoFJS, Fork me on Github: https://github.com/EnoF/EnoFJS */!function(a){"use strict";void 0!==a?(a.module={},a.require=function(b){return a.module[b]||a},a.exports=function(b,c,d){a.module[d]=c}):module.exports={require:require,exports:function(a,b){a.exports=b}}}(this.window); \ No newline at end of file diff --git a/dist/enofjs/min.whereIt.js b/dist/enofjs/min.whereIt.js new file mode 100644 index 0000000..6a3d77e --- /dev/null +++ b/dist/enofjs/min.whereIt.js @@ -0,0 +1 @@ +/* !!EnoFJS!! Version: 2.0.0, Author: EnoF (http://enof.github.io/EnoFJS, Fork me on Github: https://github.com/EnoF/EnoFJS */!function(a,LinkedHashMap){"use strict";function b(b,d,e){var g=f(e);a(c(b,g),function(){d.apply(this,g)})}function c(a,b){return a+" ["+b+"]"}function d(a,b){var c,d=a.toString(),f=new LinkedHashMap;for(var g in b)b.hasOwnProperty(g)&&(c=d.indexOf(g+","),-1===c&&(c=d.indexOf(g+")")),e(c,b[g],f));return f}function e(a,b,c){for(var d=c.getFirst();d;d=d.getNext())if(a (http://enof.github.io/EnoFJS", - "version": "1.3.0", + "version": "2.0.0", "dependencies": {}, "devDependencies": { "grunt": "^0.4", diff --git a/src/ArrayConverters.js b/src/ArrayConverters.js index b6b195f..e14e564 100644 --- a/src/ArrayConverters.js +++ b/src/ArrayConverters.js @@ -1,5 +1,5 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // diff --git a/src/LinkedHashMap.js b/src/LinkedHashMap.js index 9f5c323..0941ab4 100644 --- a/src/LinkedHashMap.js +++ b/src/LinkedHashMap.js @@ -1,13 +1,15 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // // Author Andy Tang // Fork me on Github: https://github.com/EnoF/EnoFJS -(function LinkedHashMapScope(window, clazz, undefined) { +(function LinkedHashMapScope(window, module, undefined) { 'use strict'; + var clazz = window.require('./clazz.js'); + // A `Node` containing a `key` `value` pair. // The `key` supports the types integer and string. // The `value` however can be of any type. @@ -232,12 +234,5 @@ }; }); - /* istanbul ignore else */ - if (window !== undefined) { - window.LinkedHashMap = LinkedHashMap; - } else { - module.exports = LinkedHashMap; - } -}(this.window, - this.window ? this.window.clazz : - /* istanbul ignore next */ require('./ClassFactory.js'))); \ No newline at end of file + window.exports(module, LinkedHashMap, './LinkedHashMap.js'); +}(require('./node-shim.js'), module)); \ No newline at end of file diff --git a/src/Serializable.js b/src/Serializable.js index c1add83..9d3b27b 100644 --- a/src/Serializable.js +++ b/src/Serializable.js @@ -1,14 +1,16 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // // Author Andy Tang // Fork me on Github: https://github.com/EnoF/EnoFJS -(function SerializableScope(window, clazz, undefined) { +(function SerializableScope(window, module, undefined) { 'use strict'; - var Serializable = clazz(function Serializable() { + var clazz = require('./clazz.js'); + + function Serializable() { this.private = { // Deserialization for the private and protected variables. @@ -51,7 +53,7 @@ if (this.private.isNumberOrString(object)) { // When the value is a `String` or `Number` proceed to serialize. target.push(object); - } else if (object instanceof window.Serializable) { + } else if (object instanceof InnerSerializableReference) { // When the value is Serializable, serialize the object first. target.push(object.serialize()); } @@ -88,14 +90,10 @@ this.private.deserialize(serialized); }; - }); - - /* istanbul ignore else */ - if (window !== undefined) { - window.Serializable = Serializable; - } else { - module.exports = Serializable; } -}(this.window, - this.window ? this.window.clazz : - /* istanbul ignore next */ require('./ClassFactory.js'))); \ No newline at end of file + + var SerializableClass = clazz(Serializable); + var InnerSerializableReference = SerializableClass; + + window.exports(module, SerializableClass, './Serializable.js'); +}(require('./node-shim.js'), module)); \ No newline at end of file diff --git a/src/ClassFactory.js b/src/clazz.js similarity index 97% rename from src/ClassFactory.js rename to src/clazz.js index 0305d43..de93adb 100644 --- a/src/ClassFactory.js +++ b/src/clazz.js @@ -1,11 +1,11 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // // Author Andy Tang // Fork me on Github: https://github.com/EnoF/EnoFJS -(function ClassScope(exports, undefined) { +(function ClassScope(window, module, undefined) { 'use strict'; // A map containing all classes registered to the ClassFactory. @@ -309,10 +309,5 @@ }; // Publish the module to the available source. - /* istanbul ignore else */ - if (exports.window !== undefined) { - exports.clazz = clazz; - } else { - exports.exports = clazz; - } -}(this.window || /* istanbul ignore next: only node should use module */ module)); \ No newline at end of file + window.exports(module, clazz, './clazz.js'); +}(require('./node-shim.js'), module)); \ No newline at end of file diff --git a/src/node-shim.js b/src/node-shim.js new file mode 100644 index 0000000..a51f019 --- /dev/null +++ b/src/node-shim.js @@ -0,0 +1,34 @@ +// EnoFJS +// Version: 2.0.0 +// +// Copyright (c) 2014. +// +// Author Andy Tang +// Fork me on Github: https://github.com/EnoF/EnoFJS + +(function nodeShimScope(window) { + 'use strict'; + + if (window !== undefined) { + // A namespace for our modules to be published on. + window.module = {}; + + // To unify the way commonjs is used. + window.require = function require(moduleName) { + return window.module[moduleName] || window; + }; + + // To unify the way we can export modules. + window.exports = function exports(modules, module, moduleName) { + window.module[moduleName] = module; + }; + } else { + // Now we assume this is a node.js app. + module.exports = { + require: require, + exports: function exports(modules, moduleToExport) { + modules.exports = moduleToExport; + } + }; + } +}(this.window)); \ No newline at end of file diff --git a/src/whereIt.js b/src/whereIt.js index c6fc82d..a5aeadc 100644 --- a/src/whereIt.js +++ b/src/whereIt.js @@ -1,5 +1,5 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // @@ -87,4 +87,4 @@ } -}(window.it, window.LinkedHashMap)); \ No newline at end of file +}(window.it, require('./LinkedHashMap.js'))); \ No newline at end of file diff --git a/test/karma.conf.js b/test/karma.conf.js index 6eeb811..824244b 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -1,5 +1,5 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // @@ -16,6 +16,8 @@ module.exports = function (config) { // list of files / patterns to load in the browser files: [ + 'src/node-shim.js', + 'src/clazz.js', 'src/*.js', 'test/spec/*.js' ], diff --git a/test/nodifyTest.js b/test/nodifyTest.js index c10ca45..f2d176f 100644 --- a/test/nodifyTest.js +++ b/test/nodifyTest.js @@ -1,5 +1,5 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // diff --git a/test/spec/ArrayConvertersSpec.js b/test/spec/ArrayConvertersSpec.js index e2a0a57..4758544 100644 --- a/test/spec/ArrayConvertersSpec.js +++ b/test/spec/ArrayConvertersSpec.js @@ -1,5 +1,5 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // diff --git a/test/spec/ClassFactorySpec.js b/test/spec/ClassFactorySpec.js index d4088cf..a26f569 100644 --- a/test/spec/ClassFactorySpec.js +++ b/test/spec/ClassFactorySpec.js @@ -1,5 +1,5 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // @@ -7,6 +7,7 @@ // Fork me on Github: https://github.com/EnoF/EnoFJS (function (undefined) { 'use strict'; + var clazz = require('./clazz.js'); describe('Class factory', function classFactorySpecs() { diff --git a/test/spec/LinkedHashMapSpec.js b/test/spec/LinkedHashMapSpec.js index df981d3..35efa15 100644 --- a/test/spec/LinkedHashMapSpec.js +++ b/test/spec/LinkedHashMapSpec.js @@ -1,5 +1,5 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // @@ -8,6 +8,8 @@ (function LinkedHashMapSpecScope(undefined) { 'use strict'; + var LinkedHashMap = require('./LinkedHashMap.js'); + describe('LinkedHashMap', function LinkedHashMapSpec() { describe('initalizing an LinkedHashMap', function initializingLinkedHashMap() { diff --git a/test/spec/SerializableSpec.js b/test/spec/SerializableSpec.js index a6bfa12..6c00783 100644 --- a/test/spec/SerializableSpec.js +++ b/test/spec/SerializableSpec.js @@ -1,5 +1,5 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. // @@ -8,6 +8,8 @@ (function SerializableSpecScope() { 'use strict'; + var clazz = require('./clazz.js'); + describe('Serializable specs', function SerializableSpec() { var serializable; diff --git a/test/spec/whereItSpec.js b/test/spec/whereItSpec.js index 100b730..2422b6a 100644 --- a/test/spec/whereItSpec.js +++ b/test/spec/whereItSpec.js @@ -1,5 +1,5 @@ // EnoFJS -// Version: 1.3.0 +// Version: 2.0.0 // // Copyright (c) 2014. //