Browse files

- moved to using catn8 for building m8 file

- added method m8.guid for generating guids
  • Loading branch information...
1 parent 6a672e8 commit bf491ad4f072561c955b289326441222d9ca2662 @constantology committed Sep 14, 2012
Showing with 81 additions and 105 deletions.
  1. +10 −0 .catn8
  2. +9 −0 README.md
  3. +0 −59 build.js
  4. +0 −10 build.json
  5. +31 −14 m8.js
  6. +1 −1 m8.min.js
  7. +4 −8 package.json
  8. +6 −6 src/expose.js
  9. +16 −5 src/lib.js
  10. +4 −2 src/vars.js
View
10 .catn8
@@ -0,0 +1,10 @@
+{
+ "source" : {
+ "dir" : "./src",
+ "files" : ["vars", "lib", "lib.x", "nativex", "expose"]
+ },
+ "target" : {
+ "dir" : "{pwd}"
+ },
+ "type" : "application/javascript"
+}
View
9 README.md
@@ -416,6 +416,15 @@ Any type passed to `m8.got` is cast as an Object before checking it contains a s
```
+### m8.guid():String
+Generates a guid/uuid, the code for this was adapted from [this gist](https://gist.github.com/2295777).
+
+```javascript
+
+ m8.guid(); // returns something like => "286cb768-df10-4466-aabf-f5cb4ba406a2"
+
+```
+
### m8.has( object:Object, key:String ):Boolean
Shortened version of `Object.prototype.hasOwnProperty.call`.
View
59 build.js
@@ -1,59 +0,0 @@
-// require modules
- var fs = require( 'fs' ),
- util = require( 'util' ),
- path = require( 'path' ),
- jsp = require( 'uglify-js' ).parser,
- pro = require( 'uglify-js' ).uglify,
- mkdirp = require( 'mkdirp' ),
- Templ8 = require( 'Templ8' );
-
-fs.readFile( process.argv[2] || './build.json', 'utf-8', function( err, data ) {
- if ( err ) throw err;
- processFiles( JSON.parse( data ) );
-} );
-
-function processFiles( params ) {
- Array.isArray( params.src.files ) || ( params.src.files = params.src.files.split( /,\s?|\s+/g ) );
- params.encoding || ( params.encoding = 'UTF-8' );
- params.file_err || ( params.file_err = 'break' );
- params.ext = params.ext.replace( /^\.+(.*)/, '$1' );
-
- var out_dir = path.resolve( util.format( '%s/%s', process.cwd(), params.out.dir || '.' ) ) + '/',
- out_file,
- src_dir = path.resolve( util.format( '%s/%s', process.cwd(), params.src.dir || '.' ) ) + '/',
- src = '',
- src_ast;
-
- fs.existsSync( out_dir ) || mkdirp.sync( out_dir, 0777 );
-
- params.src.files = ( src_dir + params.src.files.join( Templ8.format( '.{0}, {1}', params.ext, src_dir ) ) + '.' + params.ext ).split( ', ' );
- params.src.files.forEach( function( file ) {
- console.log( timestamp(), '- processing file: ', file );
-
- if ( !fs.existsSync( file ) ) {
- console.log( 'file: ', file, ' does not exist.' );
- switch ( params.file_err ) {
- case 'break' : console.log( timestamp(), ' - terminating build.' ); return;
- case 'continue' : break;
- }
- }
-
- src += Templ8.format( '\n{0}', fs.readFileSync( file, params.encoding ) );
- } );
-
- out_file = Templ8.format( '{0}{1}.{2}', out_dir, ( params.out.file || 'out' ), params.ext );
- console.log( timestamp(), '- writing file: ', out_file );
-
- src_ast = jsp.parse( src );
-
- fs.writeFileSync( out_file, src, params.encoding );
-// fs.writeFileSync( out_file, pro.gen_code( src_ast, { beautify : true, space_colon : true } ), params.encoding );
-
- if ( params.out.min ) {
- out_file = Templ8.format( '{0}{1}.{2}', out_dir, params.out.min, params.ext );
- console.log( timestamp(), '- writing minified file: ', out_file );
- fs.writeFileSync( out_file, pro.gen_code( pro.ast_squeeze( pro.ast_mangle( src_ast ) ) ), params.encoding );
- }
-}
-
-function timestamp() { return ( new Date() ).toISOString(); }
View
10 build.json
@@ -1,10 +0,0 @@
-{
- "encoding" : "UTF-8",
- "ext" : "js",
- "file_err" : "continue",
- "out" : { "dir" : "./", "file" : "m8", "min" : "m8.min" },
- "src" : {
- "dir" : "./src",
- "files" : ["_begin", "vars", "lib", "lib.x", "nativex", "expose", "_end"]
- }
-}
View
45 m8.js
@@ -1,7 +1,7 @@
-
;!function( root, Name, PACKAGE ) {
"use strict";
+/*~ m8/src/vars.js ~*/
// if ENV === commonjs we want root to be global
typeof global == 'undefined' ? root : ( root = global );
@@ -41,14 +41,17 @@
delete modes[UNDEF];
return modes;
}(),
- re_global = /global|window/i, re_lib = new RegExp( '^\\u005E?' + Name ),
+ randy = Math.random, re_global = /global|window/i,
+ re_guid = /[xy]/g, re_lib = new RegExp( '^\\u005E?' + Name ),
re_name = /[\s\(]*function([^\(]+).*/, re_vendor = /^[Ww]ebkit|[Mm]oz|O|[Mm]s|[Kk]html(.*)$/,
- slice = Array.prototype.slice, types = { '[object Object]' : 'object' },
+ slice = Array.prototype.slice, tpl_guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx',
+ types = { '[object Object]' : 'object' },
xcache = {
'Array' : [], 'Boolean' : [], 'Date' : [], 'Function' : [],
'Number' : [], 'Object' : [], 'RegExp' : [], 'String' : []
};
+/*~ m8/src/lib.js ~*/
function __lib__( val ) { return val; }
function bless( ns, ctx ) {
@@ -134,11 +137,12 @@
if ( ENV == 'commonjs' && is_mod( mod ) ) mod.exports = lib;
else {
mod || ( mod = root );
- var conflict = mod[name], desc = describe( { value : lib }, 'ew' );
- ( conflict && iter( conflict ) ) // make sure if lib is already defined it's not a primitive value!
- ? def( ( lib = conflict ), '__', desc ) // don't over-write what's there, just add lib to conflict as conflict.__
- : def( mod, name, desc ); // however, all properties will be added to conflict, not lib and
- } // conflict will be returned instead of lib
+ var conflict = mod[name],
+ desc = describe( { value : lib }, 'ew' ); // make sure if lib is already defined it's not a primitive value!
+ ( conflict && iter( conflict ) ) // don't over-write what's there, just add lib to conflict as conflict.__
+ ? def( ( lib = conflict ), '__', desc ) // however, all properties will be added to conflict, not lib and
+ : def( mod, name, desc ); // conflict will be returned instead of lib
+ }
mod = obj(); mod[__name__] = name; mod[__type__] = 'library'; // make sure the exposed library has a type
defs( lib, mod, 'w', true ); // of "library" and its name attached to it.
@@ -149,6 +153,14 @@
function fname( fn ) { return fn.name || fn.displayName || ( String( fn ).match( re_name ) || ['', ''] )[1].trim(); }
function got( obj, key ) { return arguments.length > 2 ? hasSome( got, obj, Array.coerce( arguments, 1 ) ) : key in Object( obj ); }
+
+ // credit for guid goes here: gist.github.com/2295777
+ function guid() { return tpl_guid.replace( re_guid, guid_replace ); }
+ function guid_replace( match ) {
+ var num = ( randy() * 16 ) | 0;
+ return ( match == 'x' ? num : ( num & 0x3 | 0x8 ) ).toString( 16 );
+ }
+
function has( obj, key ) { return arguments.length > 2 ? hasSome( has, obj, Array.coerce( arguments, 1 ) ) : OP.hasOwnProperty.call( obj, key ); }
function hasSome( test, obj, keys ) { return keys.some( function( key ) { return test( obj, key ); } ); }
@@ -196,6 +208,8 @@
return o;
}
+ function noop() {}
+
function obj( props ) {
var nobj = Object.create( null );
return typeof props == 'object' ? copy( nobj, props ) : nobj;
@@ -242,6 +256,7 @@
: UNDEF;
}
+/*~ m8/src/lib.x.js ~*/
// Commonjs Modules 1.1.1: http://wiki.commonjs.org/wiki/Modules/1.1.1
// notes section: http://wiki.commonjs.org/wiki/Modules/ProposalForNativeExtension
// specifies the possibility of sandboxing JavaScript Natives in Modules in future versions
@@ -268,6 +283,7 @@
Type[__xid__] = extenders.length; // assigned every time __lib__.x() is called, and
} // potentilly throwing overwrite errors.
+/*~ m8/src/nativex.js ~*/
x.cache( 'Array', function( Type ) {
def( Type, 'coerce', function( a, i, j ) {
if ( !got( a, 'length' ) ) return [a];
@@ -381,17 +397,18 @@
}, 'w' );
} );
+/*~ m8/src/expose.js ~*/
iter( PACKAGE ) || ( PACKAGE = ENV == 'commonjs' ? module : root );
defs( ( __lib__ = expose( __lib__, Name, PACKAGE ) ), {
// properties
- ENV : ENV, global : { value : root }, modes : { value : modes },
+ ENV : ENV, global : { value : root }, modes : { value : modes },
// methods
- bless : bless, coerce : coerce, copy : copy, def : def, defs : defs,
- describe : describe, empty : empty, exists : exists, expose : expose, got : got,
- has : has, id : id, iter : iter, len : len, merge : merge,
- nativeType : nativeType, noop : function() {}, obj : obj, range : range,
- remove : remove, tostr : tostr, type : type, valof : valof, x : x
+ bless : bless, coerce : coerce, copy : copy, def : def, defs : defs,
+ describe : describe, empty : empty, exists : exists, expose : expose, got : got,
+ guid : guid, has : has, id : id, iter : iter, len : len,
+ merge : merge, nativeType : nativeType, noop : noop, obj : obj, range : range,
+ remove : remove, tostr : tostr, type : type, valof : valof, x : x
}, 'w' );
x( Object, Array, Boolean, Function );
View
2 m8.min.js
@@ -1 +1 @@
-!function(e,t,n){"use strict";function S(e){return e}function x(e,t){switch(Z(e)){case"array":break;case"string":e=e.split(".");break;default:return T(t)}m.test(e[0])&&(t=S,e.shift());if(!e.length)return T(t);e[0].indexOf("^")||(t||e[0]=="^"?e.shift():e[0]=e[0].substring(1)),t=T(t);var n;while(n=e.shift())t=t[n]||(t[n]=X());return t}function T(t){return s=="commonjs"?t?I(t)?t.exports:t:module.exports:t||e}function N(e){var t=Number(e),n;return isNaN(t)?(n=String(e))in f?f[n]:e:t}function C(e,t,n){n=n===!0,t||(t=e,e=X());for(var r in t)!H(t,r)||n&&H(e,r)||(e[r]=t[r]);return e}function k(e,n,r){var i=b.call(arguments,3),s=P(e,n),o,u,a,f;switch(Z(i[0])){case"string":u=d[i.shift()];break;case"object":u=i.shift();break;default:a=Z(r),u=a!="object"&&s?Object.getOwnPropertyDescriptor(e,n):null,!u||(u=a=="function"?d.cw:d.cew)}return f=i.shift()===!0,o=i.shift()===!0,s&&!f?o&&new Error(t+".def cannot overwrite existing property: "+n+", in item type: "+et(e)+"."):(a!="object"&&u&&(r=A(r,u)),(r.get||r.set)&&delete r.writable,Object.defineProperty(e,n,r)),S}function L(e,t,n,r,i){n||(n="cw");for(var s in t)!H(t,s)||k(e,s,t[s],n,r,i);return S}function A(e,t){return C(Z(e)=="object"?e:{value:e},Z(t)=="object"?t:d[String(t).toLowerCase()]||d.cew,!0)}function O(e){return!M(e)||!R(e)&&q(e)||!1}function M(e){return!(e===null||e===u||typeof e=="number"&&isNaN(e))}function _(t,n,i){typeof n!="string"&&t[r]&&(i=n,n=t[r]);if(s=="commonjs"&&I(i))i.exports=t;else{i||(i=e);var o=i[n],u=A({value:t},"ew");o&&q(o)?k(t=o,"__",u):k(i,n,u)}return i=X(),i[r]=n,i[__type__]="library",L(t,i,"w",!0),t}function D(e){return e.name||e.displayName||(String(e).match(g)||["",""])[1].trim()}function P(e,t){return arguments.length>2?B(P,e,Array.coerce(arguments,1)):t in Object(e)}function H(e,t){return arguments.length>2?B(H,e,Array.coerce(arguments,1)):o.hasOwnProperty.call(e,t)}function B(e,t,n){return n.some(function(n){return e(t,n)})}function j(e,t){return e?P(e,"id")&&!O(e.id)?e.id:e.id=F(t):F(t)}function F(e){return(e||p)+"-"+ ++h}function I(e){if(a===null)return!1;try{return e instanceof a}catch(t){return!1}}function q(e){return P(e,"length")||Z(e)=="object"}function R(e){return("length"in(e=Object(e))?e:Object.keys(e)).length}function U(e,t){var n;if(!t)switch(n=Z(e)){case"array":case"object":t=e,e=new(t.constructor||Object);break;default:return e}else n=Z(t);switch(n){case"object":return Object.keys(t).reduce(W,{source:t,target:e}).target;case"array":return e.length=t.length,t.reduce(z,e);default:return t}}function z(e,t,n){return e[n]=Z(e[n])===Z(t)?U(e[n],t):U(t),e}function W(e,t){return e.target[t]=Z(e.target[t])===Z(e.source[t])?U(e.target[t],e.source[t]):U(e.source[t]),e}function X(e){var t=Object.create(null);return typeof e=="object"?C(t,e):t}function V(e,t){var n=[e];while(++e<=t)n.push(e);return n}function $(e,t){t=Array.isArray(t)?t:b.call(arguments,1);var n=Array.isArray(e)?J:K;return t.forEach(n,e),e}function J(e){var t=this.indexOf(e);t=~t?t:!isNaN(e)&&e in this?e:t,t<0||this.splice(t,1)}function K(e){delete this[e]}function Q(e){return o.toString.call(e)}function G(e){return o.valueOf.call(e)}function Y(e){return e==c?c:e==l||e=="nodelist"?l:!e.indexOf("htm")&&e.lastIndexOf("element")+7===e.length?"htmlelement":!1}function Z(e){var t=Q(e);return t in w?w[t]:w[t]=t.split(" ")[1].split("]")[0].replace(y,"$1").toLowerCase()}function et(e){return e===null||e===u?!1:P(e,__type__)?e[__type__]:Object.getPrototypeOf(e)===null?"nullobject":u}function tt(){return b.call(arguments).forEach(rt),S}function nt(e){e(this,S)}function rt(e){P(e,i)||k(e,i,0,"w");var t=E[e[r]||D(e)];if(!t)return;t.slice(e[i]).forEach(nt,e),e[i]=t.length}typeof global=="undefined"?e:e=global;var r="__name__",__type__="__type__",i="__xid__",s=typeof module!="undefined"&&"exports"in module&&typeof require=="function"?"commonjs":typeof navigator!="undefined"?"browser":"other",o=Object.prototype,u,a=s!="commonjs"?null:require("module"),f=[!1,NaN,null,!0,u].reduce(function(e,t){return e[String(t)]=t,e},X()),l="htmlcollection",c="htmldocument",h=999,p="anon",d=function(){var e={ce:"ec",cw:"wc",ew:"we",cew:"cwe ecw ewc wce wec".split(" ")},t="configurable enumerable writable".split(" "),n={c:[!0,!1,!1],ce:[!0,!0,!1],cew:[!0,!0,!0],cw:[!0,!1,!0],e:[!1,!0,!1],ew:[!1,!0,!0],r:[!1,!1,!1],w:[!1,!1,!0]},r=Object.keys(n).reduce(function(r,i){function s(e){r[e]=r[i]}var o=e[i];return r[i]=t.reduce(function(e,t,r){return e[t]=n[i][r],e},X()),!o||(Array.isArray(o)?o.forEach(s):s(o)),r},X());return delete r[u],r}(),v=/global|window/i,m=new RegExp("^\\u005E?"+t),g=/[\s\(]*function([^\(]+).*/,y=/^[Ww]ebkit|[Mm]oz|O|[Mm]s|[Kk]html(.*)$/,b=Array.prototype.slice,w={"[object Object]":"object"},E={Array:[],Boolean:[],Date:[],Function:[],Number:[],Object:[],RegExp:[],String:[]};k(tt,"cache",function(e,t){return typeof e=="string"||(e=e[r]||D(e)),E[e]||(E[e]=[]),E[e].push(t),S},"w"),tt.cache("Array",function(e){k(e,"coerce",function(e,t,n){return P(e,"length")?(t=et(t)=="number"?t>0?t:0:0,n=et(n)=="number"?n>t?n:n<=0?e.length+n:t+n:e.length,b.call(e,t,n)):[e]},"w"),k(e.prototype,"find",function(e,t){var n=-1,r=this.length>>>0;t||(t=this);while(++n<r)if(!!e.call(t,this[n],n,this))return this[n];return null},"w")}),tt.cache("Boolean",function(e){k(e,"coerce",function(e){switch(et(e)){case"boolean":return e;case"nan":case!1:return!1;case"number":case"string":return e in f?!!f[e]:Number(e)!==0}return!0},"w")}),tt.cache("Function",function(e){function t(e){return!e||e in o}function n(){return this.toString()}function i(){return this}var s="__xname__",o={Anonymous:!0,anonymous:!0},u={mimic:function(e,t){var r=e.valueOf();return L(this,{displayName:t||D(r),toString:n.bind(r),valueOf:i.bind(r)},"c",!0),this}};u[r]={get:function(){if(!this[s]){var e=this.valueOf(),n=e!==this?t(e[r])?null:e[r]:null,i=n||D(this);!t(i)||t(this.displayName)||(i=this.displayName),k(this,s,i||"anonymous","w")}return this[s]}},L(e.prototype,u,"w"),k(e,"anon_list",{value:o},"w")}),tt.cache("Object",function(e){k(e.prototype,__type__,C({get:function(){var e,t=this,n=t.constructor,i=Z(t),s=Y(i)||(v.test(i)?"global":!1);return s?s:i=="number"?isNaN(t)?"nan":"number":i=="object"&&typeof n=="function"&&n[__type__]!="function"?(e=String(n[r]).toLowerCase(),!e||e=="anonymous"?n[__type__]||i:e):i}},d.r)),L(e,{key:function(t,n){return e.keys(e(t)).find(function(e){return t[e]===n})},reduce:function(t,n,r){return e.keys(e(t)).reduce(function(e,r,i){return e=n.call(t,e,t[r],r,t,i),e},r)},value:function(t,n){if(isNaN(n)){if(P(t,n))return t[n];if(!!~n.indexOf(".")){var r;n=n.split(".");while(r=n.shift())if((t=e.value(t,r))===u)break;return t}}return O(t)?u:M(t[n])?t[n]:typeof t.get=="function"?t.get(n):typeof t.getAttribute=="function"?t.getAttribute(n):u},values:function(t){return e.keys(Object(t)).map(function(e){return t[e]})}},"w")}),q(n)||(n=s=="commonjs"?module:e),L(S=_(S,t,n),{ENV:s,global:{value:e},modes:{value:d},bless:x,coerce:N,copy:C,def:k,defs:L,describe:A,empty:O,exists:M,expose:_,got:P,has:H,id:j,iter:q,len:R,merge:U,nativeType:Z,noop:function(){},obj:X,range:V,remove:$,tostr:Q,type:et,valof:G,x:tt},"w"),tt(Object,Array,Boolean,Function)}(this,"m8")
+!function(e,t,n){"use strict";function N(e){return e}function C(e,t){switch(st(e)){case"array":break;case"string":e=e.split(".");break;default:return k(t)}y.test(e[0])&&(t=N,e.shift());if(!e.length)return k(t);e[0].indexOf("^")||(t||e[0]=="^"?e.shift():e[0]=e[0].substring(1)),t=k(t);var n;while(n=e.shift())t=t[n]||(t[n]=G());return t}function k(t){return s=="commonjs"?t?W(t)?t.exports:t:module.exports:t||e}function L(e){var t=Number(e),n;return isNaN(t)?(n=String(e))in f?f[n]:e:t}function A(e,t,n){n=n===!0,t||(t=e,e=G());for(var r in t)!q(t,r)||n&&q(e,r)||(e[r]=t[r]);return e}function O(e,n,r){var i=E.call(arguments,3),s=j(e,n),o,u,a,f;switch(st(i[0])){case"string":u=d[i.shift()];break;case"object":u=i.shift();break;default:a=st(r),u=a!="object"&&s?Object.getOwnPropertyDescriptor(e,n):null,!u||(u=a=="function"?d.cw:d.cew)}return f=i.shift()===!0,o=i.shift()===!0,s&&!f?o&&new Error(t+".def cannot overwrite existing property: "+n+", in item type: "+ot(e)+"."):(a!="object"&&u&&(r=_(r,u)),(r.get||r.set)&&delete r.writable,Object.defineProperty(e,n,r)),N}function M(e,t,n,r,i){n||(n="cw");for(var s in t)!q(t,s)||O(e,s,t[s],n,r,i);return N}function _(e,t){return A(st(e)=="object"?e:{value:e},st(t)=="object"?t:d[String(t).toLowerCase()]||d.cew,!0)}function D(e){return!P(e)||!V(e)&&X(e)||!1}function P(e){return!(e===null||e===u||typeof e=="number"&&isNaN(e))}function H(t,n,i){typeof n!="string"&&t[r]&&(i=n,n=t[r]);if(s=="commonjs"&&W(i))i.exports=t;else{i||(i=e);var o=i[n],u=_({value:t},"ew");o&&X(o)?O(t=o,"__",u):O(i,n,u)}return i=G(),i[r]=n,i[__type__]="library",M(t,i,"w",!0),t}function B(e){return e.name||e.displayName||(String(e).match(b)||["",""])[1].trim()}function j(e,t){return arguments.length>2?R(j,e,Array.coerce(arguments,1)):t in Object(e)}function F(){return S.replace(g,I)}function I(e){var t=v()*16|0;return(e=="x"?t:t&3|8).toString(16)}function q(e,t){return arguments.length>2?R(q,e,Array.coerce(arguments,1)):o.hasOwnProperty.call(e,t)}function R(e,t,n){return n.some(function(n){return e(t,n)})}function U(e,t){return e?j(e,"id")&&!D(e.id)?e.id:e.id=z(t):z(t)}function z(e){return(e||p)+"-"+ ++h}function W(e){if(a===null)return!1;try{return e instanceof a}catch(t){return!1}}function X(e){return j(e,"length")||st(e)=="object"}function V(e){return("length"in(e=Object(e))?e:Object.keys(e)).length}function $(e,t){var n;if(!t)switch(n=st(e)){case"array":case"object":t=e,e=new(t.constructor||Object);break;default:return e}else n=st(t);switch(n){case"object":return Object.keys(t).reduce(K,{source:t,target:e}).target;case"array":return e.length=t.length,t.reduce(J,e);default:return t}}function J(e,t,n){return e[n]=st(e[n])===st(t)?$(e[n],t):$(t),e}function K(e,t){return e.target[t]=st(e.target[t])===st(e.source[t])?$(e.target[t],e.source[t]):$(e.source[t]),e}function Q(){}function G(e){var t=Object.create(null);return typeof e=="object"?A(t,e):t}function Y(e,t){var n=[e];while(++e<=t)n.push(e);return n}function Z(e,t){t=Array.isArray(t)?t:E.call(arguments,1);var n=Array.isArray(e)?et:tt;return t.forEach(n,e),e}function et(e){var t=this.indexOf(e);t=~t?t:!isNaN(e)&&e in this?e:t,t<0||this.splice(t,1)}function tt(e){delete this[e]}function nt(e){return o.toString.call(e)}function rt(e){return o.valueOf.call(e)}function it(e){return e==c?c:e==l||e=="nodelist"?l:!e.indexOf("htm")&&e.lastIndexOf("element")+7===e.length?"htmlelement":!1}function st(e){var t=nt(e);return t in x?x[t]:x[t]=t.split(" ")[1].split("]")[0].replace(w,"$1").toLowerCase()}function ot(e){return e===null||e===u?!1:j(e,__type__)?e[__type__]:Object.getPrototypeOf(e)===null?"nullobject":u}function ut(){return E.call(arguments).forEach(ft),N}function at(e){e(this,N)}function ft(e){j(e,i)||O(e,i,0,"w");var t=T[e[r]||B(e)];if(!t)return;t.slice(e[i]).forEach(at,e),e[i]=t.length}typeof global=="undefined"?e:e=global;var r="__name__",__type__="__type__",i="__xid__",s=typeof module!="undefined"&&"exports"in module&&typeof require=="function"?"commonjs":typeof navigator!="undefined"?"browser":"other",o=Object.prototype,u,a=s!="commonjs"?null:require("module"),f=[!1,NaN,null,!0,u].reduce(function(e,t){return e[String(t)]=t,e},G()),l="htmlcollection",c="htmldocument",h=999,p="anon",d=function(){var e={ce:"ec",cw:"wc",ew:"we",cew:"cwe ecw ewc wce wec".split(" ")},t="configurable enumerable writable".split(" "),n={c:[!0,!1,!1],ce:[!0,!0,!1],cew:[!0,!0,!0],cw:[!0,!1,!0],e:[!1,!0,!1],ew:[!1,!0,!0],r:[!1,!1,!1],w:[!1,!1,!0]},r=Object.keys(n).reduce(function(r,i){function s(e){r[e]=r[i]}var o=e[i];return r[i]=t.reduce(function(e,t,r){return e[t]=n[i][r],e},G()),!o||(Array.isArray(o)?o.forEach(s):s(o)),r},G());return delete r[u],r}(),v=Math.random,m=/global|window/i,g=/[xy]/g,y=new RegExp("^\\u005E?"+t),b=/[\s\(]*function([^\(]+).*/,w=/^[Ww]ebkit|[Mm]oz|O|[Mm]s|[Kk]html(.*)$/,E=Array.prototype.slice,S="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",x={"[object Object]":"object"},T={Array:[],Boolean:[],Date:[],Function:[],Number:[],Object:[],RegExp:[],String:[]};O(ut,"cache",function(e,t){return typeof e=="string"||(e=e[r]||B(e)),T[e]||(T[e]=[]),T[e].push(t),N},"w"),ut.cache("Array",function(e){O(e,"coerce",function(e,t,n){return j(e,"length")?(t=ot(t)=="number"?t>0?t:0:0,n=ot(n)=="number"?n>t?n:n<=0?e.length+n:t+n:e.length,E.call(e,t,n)):[e]},"w"),O(e.prototype,"find",function(e,t){var n=-1,r=this.length>>>0;t||(t=this);while(++n<r)if(!!e.call(t,this[n],n,this))return this[n];return null},"w")}),ut.cache("Boolean",function(e){O(e,"coerce",function(e){switch(ot(e)){case"boolean":return e;case"nan":case!1:return!1;case"number":case"string":return e in f?!!f[e]:Number(e)!==0}return!0},"w")}),ut.cache("Function",function(e){function t(e){return!e||e in o}function n(){return this.toString()}function i(){return this}var s="__xname__",o={Anonymous:!0,anonymous:!0},u={mimic:function(e,t){var r=e.valueOf();return M(this,{displayName:t||B(r),toString:n.bind(r),valueOf:i.bind(r)},"c",!0),this}};u[r]={get:function(){if(!this[s]){var e=this.valueOf(),n=e!==this?t(e[r])?null:e[r]:null,i=n||B(this);!t(i)||t(this.displayName)||(i=this.displayName),O(this,s,i||"anonymous","w")}return this[s]}},M(e.prototype,u,"w"),O(e,"anon_list",{value:o},"w")}),ut.cache("Object",function(e){O(e.prototype,__type__,A({get:function(){var e,t=this,n=t.constructor,i=st(t),s=it(i)||(m.test(i)?"global":!1);return s?s:i=="number"?isNaN(t)?"nan":"number":i=="object"&&typeof n=="function"&&n[__type__]!="function"?(e=String(n[r]).toLowerCase(),!e||e=="anonymous"?n[__type__]||i:e):i}},d.r)),M(e,{key:function(t,n){return e.keys(e(t)).find(function(e){return t[e]===n})},reduce:function(t,n,r){return e.keys(e(t)).reduce(function(e,r,i){return e=n.call(t,e,t[r],r,t,i),e},r)},value:function(t,n){if(isNaN(n)){if(j(t,n))return t[n];if(!!~n.indexOf(".")){var r;n=n.split(".");while(r=n.shift())if((t=e.value(t,r))===u)break;return t}}return D(t)?u:P(t[n])?t[n]:typeof t.get=="function"?t.get(n):typeof t.getAttribute=="function"?t.getAttribute(n):u},values:function(t){return e.keys(Object(t)).map(function(e){return t[e]})}},"w")}),X(n)||(n=s=="commonjs"?module:e),M(N=H(N,t,n),{ENV:s,global:{value:e},modes:{value:d},bless:C,coerce:L,copy:A,def:O,defs:M,describe:_,empty:D,exists:P,expose:H,got:j,guid:F,has:q,id:U,iter:X,len:V,merge:$,nativeType:st,noop:Q,obj:G,range:Y,remove:Z,tostr:nt,type:ot,valof:rt,x:ut},"w"),ut(Object,Array,Boolean,Function)}(this,"m8")
View
12 package.json
@@ -6,13 +6,9 @@
},
"description" : "m8 is a small utility library you might find useful or just plain annoying.",
"devDependencies" : {
- "Templ8" : ">= 0.3.0",
- "chai" : ">= 1.2.7",
- "mkdirp" : ">= 0.3.0",
- "mime" : ">= 1.2.0",
- "mocha" : ">= 1.3.0",
- "n8iv" : ">= 0.2.0",
- "uglify-js" : ">= 1.2.5"
+ "catn8" : ">= 0.0.2",
+ "chai" : ">= 1.2.0",
+ "mocha" : ">= 1.4.2"
},
"engines" : {
"node" : ">= 0.4.x"
@@ -31,5 +27,5 @@
"scripts" : {
"test" : "mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"
},
- "version" : "0.2.6"
+ "version" : "0.2.7"
}
View
12 src/expose.js
@@ -2,13 +2,13 @@
defs( ( __lib__ = expose( __lib__, Name, PACKAGE ) ), {
// properties
- ENV : ENV, global : { value : root }, modes : { value : modes },
+ ENV : ENV, global : { value : root }, modes : { value : modes },
// methods
- bless : bless, coerce : coerce, copy : copy, def : def, defs : defs,
- describe : describe, empty : empty, exists : exists, expose : expose, got : got,
- has : has, id : id, iter : iter, len : len, merge : merge,
- nativeType : nativeType, noop : function() {}, obj : obj, range : range,
- remove : remove, tostr : tostr, type : type, valof : valof, x : x
+ bless : bless, coerce : coerce, copy : copy, def : def, defs : defs,
+ describe : describe, empty : empty, exists : exists, expose : expose, got : got,
+ guid : guid, has : has, id : id, iter : iter, len : len,
+ merge : merge, nativeType : nativeType, noop : noop, obj : obj, range : range,
+ remove : remove, tostr : tostr, type : type, valof : valof, x : x
}, 'w' );
x( Object, Array, Boolean, Function );
View
21 src/lib.js
@@ -83,11 +83,12 @@
if ( ENV == 'commonjs' && is_mod( mod ) ) mod.exports = lib;
else {
mod || ( mod = root );
- var conflict = mod[name], desc = describe( { value : lib }, 'ew' );
- ( conflict && iter( conflict ) ) // make sure if lib is already defined it's not a primitive value!
- ? def( ( lib = conflict ), '__', desc ) // don't over-write what's there, just add lib to conflict as conflict.__
- : def( mod, name, desc ); // however, all properties will be added to conflict, not lib and
- } // conflict will be returned instead of lib
+ var conflict = mod[name],
+ desc = describe( { value : lib }, 'ew' ); // make sure if lib is already defined it's not a primitive value!
+ ( conflict && iter( conflict ) ) // don't over-write what's there, just add lib to conflict as conflict.__
+ ? def( ( lib = conflict ), '__', desc ) // however, all properties will be added to conflict, not lib and
+ : def( mod, name, desc ); // conflict will be returned instead of lib
+ }
mod = obj(); mod[__name__] = name; mod[__type__] = 'library'; // make sure the exposed library has a type
defs( lib, mod, 'w', true ); // of "library" and its name attached to it.
@@ -98,6 +99,14 @@
function fname( fn ) { return fn.name || fn.displayName || ( String( fn ).match( re_name ) || ['', ''] )[1].trim(); }
function got( obj, key ) { return arguments.length > 2 ? hasSome( got, obj, Array.coerce( arguments, 1 ) ) : key in Object( obj ); }
+
+ // credit for guid goes here: gist.github.com/2295777
+ function guid() { return tpl_guid.replace( re_guid, guid_replace ); }
+ function guid_replace( match ) {
+ var num = ( randy() * 16 ) | 0;
+ return ( match == 'x' ? num : ( num & 0x3 | 0x8 ) ).toString( 16 );
+ }
+
function has( obj, key ) { return arguments.length > 2 ? hasSome( has, obj, Array.coerce( arguments, 1 ) ) : OP.hasOwnProperty.call( obj, key ); }
function hasSome( test, obj, keys ) { return keys.some( function( key ) { return test( obj, key ); } ); }
@@ -145,6 +154,8 @@
return o;
}
+ function noop() {}
+
function obj( props ) {
var nobj = Object.create( null );
return typeof props == 'object' ? copy( nobj, props ) : nobj;
View
6 src/vars.js
@@ -37,9 +37,11 @@
delete modes[UNDEF];
return modes;
}(),
- re_global = /global|window/i, re_lib = new RegExp( '^\\u005E?' + Name ),
+ randy = Math.random, re_global = /global|window/i,
+ re_guid = /[xy]/g, re_lib = new RegExp( '^\\u005E?' + Name ),
re_name = /[\s\(]*function([^\(]+).*/, re_vendor = /^[Ww]ebkit|[Mm]oz|O|[Mm]s|[Kk]html(.*)$/,
- slice = Array.prototype.slice, types = { '[object Object]' : 'object' },
+ slice = Array.prototype.slice, tpl_guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx',
+ types = { '[object Object]' : 'object' },
xcache = {
'Array' : [], 'Boolean' : [], 'Date' : [], 'Function' : [],
'Number' : [], 'Object' : [], 'RegExp' : [], 'String' : []

0 comments on commit bf491ad

Please sign in to comment.