Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- fixed issue with and added test for private variable `re_gsub` fail…

…ing to interpolate correctly under certain conditions

- added boolean flag `m8.AMD`
- added method `m8.define` which — if `m8.AMD === true` — wraps the passed module in an amd style define block
  • Loading branch information...
commit 235be8339c32ee48dc83fe5640a2e2b2e70c88b4 1 parent 454e7e7
@constantology authored
View
52 m8.js
@@ -7,6 +7,7 @@
var __name__ = '__name__', __type__ = '__type__', __xid__ = '__xid__',
// it's a best guess as to whether the environment we're in is a browser, commonjs platform (like nodejs) or something else completely
+ AMD = typeof define == 'function' && define.amd,
ENV = typeof module != 'undefined' && 'exports' in module && typeof require == 'function' ? 'commonjs' : typeof navigator != 'undefined' ? 'browser' : 'other',
OP = Object.prototype, UNDEF,
// this will be used by the bless method to check if a context root is a commonjs module or not.
@@ -50,7 +51,7 @@
return cache;
}, obj() ),
randy = Math.random, re_global = /global|window/i,
- re_gsub = /\$?\{([^\}]+)\}/g, re_guid = /[xy]/g, re_lib = new RegExp( '^\\u005E?' + Name ),
+ re_gsub = /\$?\{([^\}'"]+)\}/g, 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, tpl_guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx',
xcache = {
@@ -132,6 +133,19 @@
return __lib__;
}
+ function define_amd( path, deps, mod ) {
+ if ( !AMD ) return;
+
+ if ( nativeType( deps ) != 'array' ) {
+ mod = deps;
+ deps = [];
+ }
+
+ define( path, deps, function() { return mod; } );
+
+ return __lib__;
+ }
+
function defs( item, props, mode, overwrite, debug ) {
mode || ( mode = 'cw' );
for ( var key in props )
@@ -170,8 +184,8 @@
else
def( mod, name, describe( { value : lib }, 'ew' ) );
- if ( ENV == 'browser' && mod === root ) // don't expose as amd if lib is being added to a module that will be exposed
- typeof define != 'function' || !define.amd || define( name, [], function() { return lib; } );
+ // don't expose as amd if lib is being added to a module that will be exposed
+ !AMD || mod !== root || define_amd( name, lib );
}
defs( lib, defaults, 'w', true );
@@ -533,23 +547,23 @@
defs( ( __lib__ = expose( __lib__, Name, PACKAGE ) ), {
// properties
- ENV : ENV, global : { value : root },
- modes : { value : modes },
+ AMD : AMD, ENV : ENV,
+ global : { value : root }, modes : { value : modes },
// methods
- bless : bless, coerce : coerce,
- copy : copy, cpdef : cpdef,
- def : def, defs : defs,
- describe : describe, description : description,
- empty : empty, exists : exists,
- expose : expose, format : format, got : prop_exists.bind( null, got ),
- gsub : gsub, guid : guid, has : prop_exists.bind( null, has ),
- id : id, iter : iter,
- len : len, merge : merge,
- nativeType : nativeType, noop : noop,
- ntype : nativeType, obj : obj,
- range : range, remove : remove,
- tostr : tostr, type : type,
- update : update, valof : valof,
+ bless : bless, coerce : coerce,
+ copy : copy, cpdef : cpdef,
+ def : def, defs : defs, define : define_amd,
+ describe : describe, description : description,
+ empty : empty, exists : exists,
+ expose : expose, format : format, got : prop_exists.bind( null, got ),
+ gsub : gsub, guid : guid, has : prop_exists.bind( null, has ),
+ id : id, iter : iter,
+ len : len, merge : merge,
+ nativeType : nativeType, noop : noop,
+ ntype : nativeType, obj : obj,
+ range : range, remove : remove,
+ tostr : tostr, type : type,
+ update : update, valof : valof,
x : x
}, 'w' );
View
2  m8.min.js
@@ -1 +1 @@
-!function(e,t,n){"use strict";function r(e){return e}function u(e,t){switch(I(e)){case"array":break;case"string":e=e.split(".");break;default:return o(t)}if(ht.test(e[0])&&(t=r,e.shift()),!e.length)return o(t);e[0].indexOf("^")||(t||"^"==e[0]?e.shift():e[0]=e[0].substring(1)),t=o(t);for(var n;n=e.shift();)t=t[n]||(t[n]=C());return t}function o(t){return"commonjs"==Z?t?_(t)?t.exports:t:module.exports:t||e}function c(e){var t,n=Number(e);return isNaN(n)?(t=e+"")in nt?nt[t]:e:n}function i(e,t,n){n=n===!0,t||(t=e,e=C());for(var r in t)!j(t,r)||n&&j(e,r)||(e[r]=t[r]);return e}function a(e,t,n){return n=n===!0,t||(t=e,e=C()),Object.getOwnPropertyNames(t).reduce(function(e,r){return n&&j(e,r)||f(e,r,p(t,r)),e},e)}function f(e,n,u){var o,c,i,a,f=dt.call(arguments,3),s=y(e,n);switch(I(f[0])){case"string":c=it[f.shift()];break;case"object":c=f.shift();break;default:i=I(u),c="object"!=i&&s?p(e,n):null,!c||(c="function"==i?it.cw:it.cew)}return a=f.shift()===!0,o=f.shift()===!0,s&&!a?o&&Error(t+".def cannot overwrite existing property: "+n+", in item type: "+K(e)+"."):("object"!=i&&c&&(u=l(u,c)),(u.get||u.set)&&delete u.writable,Object.defineProperty(e,n,u)),r}function s(e,t,n,u,o){n||(n="cw");for(var c in t)!j(t,c)||f(e,c,t[c],n,u,o);return r}function l(e,t){return i("object"==I(e)?e:{value:e},"object"==I(t)?t:it[(t+"").toLowerCase()]||it.cew,!0)}function p(e,t){return Object.getOwnPropertyDescriptor(e,t)}function h(e){return!b(e)||!A(e)&&k(e)||!1}function b(e){return!(null===e||e===J||"number"==typeof e&&isNaN(e))}function g(t,n,r){"string"!=typeof n&&t[Q]&&(r=n,n=t[Q]);var u,o=C();return o[Q]=n,o[X]="library","commonjs"==Z&&_(r)?r.exports=t:(r||(r=e),(u=r[n])&&k(u)?(u[n]=t,t=a(u,t)):f(r,n,l({value:t},"ew")),"browser"==Z&&r===e&&("function"!=typeof define||!define.amd||define(n,[],function(){return t}))),s(t,o,"w",!0),t}function d(e){return e.name||e.displayName||((e+"").match(bt)||["",""])[1].trim()}function m(e){return w(e,Array.coerce(arguments,1))}function y(e,t){return t+""in Object(e)}function w(e,t,n){return(e+"").replace(n||lt,function(e,n){return t[n]||""})}function x(){return mt.replace(pt,v)}function v(e){var t=0|16*ft();return("x"==e?t:8|3&t).toString(16)}function j(e,t){return et.hasOwnProperty.call(Object(e),t+"")}function O(e,t){return e?y(e,"id")&&!h(e.id)?e.id:e.id=N(t):N(t)}function N(e){return(e||ct)+"-"+ ++ot}function _(e){if(null===tt)return!1;try{return e instanceof tt}catch(t){return!1}}function k(e){return y(e,"length")||"object"==I(e)}function A(e){return("length"in(e=Object(e))?e:Object.keys(e)).length}function E(e,t){var n;if(t)n=I(t);else switch(n=I(e)){case"array":case"object":t=e,e=new(t.constructor||Object);break;default:return e}switch(n){case"object":return Object.keys(t).reduce(S,{source:t,target:e}).target;case"array":return e.length=t.length,t.reduce(P,e);default:return t}}function P(e,t,n){return e[n]=I(e[n])===I(t)?E(e[n],t):E(t),e}function S(e,t){return e.target[t]=I(e.target[t])===I(e.source[t])?E(e.target[t],e.source[t]):E(e.source[t]),e}function B(){}function C(e){var t=Object.create(null);return"object"==typeof e?i(t,e):t}function F(e,t,n){var r;if(n+="",arguments.length>3){for(n=dt.call(arguments,2);r=n.shift();)if(F(e,t,r))return!0;return!1}if(e(t,n))return!0;if("string"!=typeof t&&~n.indexOf(".")){for(n=n.split(".");r=n.shift();){if(!F(e,t,r))return!1;t=t[r]}return!0}return!1}function L(e,t){for(var n=[e];t>=++e;)n.push(e);return n}function D(e,t){t=Array.isArray(t)?t:dt.call(arguments,1);var n=Array.isArray(e)?M:R;return t.forEach(n,e),e}function M(e){var t=this.indexOf(e);t=~t?t:!isNaN(e)&&e in this?e:t,0>t||this.splice(t,1)}function R(e){delete this[e]}function $(e){return et.toString.call(e)}function q(e){return et.valueOf.call(e)}function z(e){return e==ut?ut:e==rt||"nodelist"==e?rt:e.indexOf("htm")||e.lastIndexOf("element")+7!==e.length?!1:"htmlelement"}function I(e){var t=$(e);return t in at?at[t]:at[t]=t.split(" ")[1].split("]")[0].replace(gt,"$1").toLowerCase()}function K(e){if(null===e||e===J)return!1;var t=y(e,X)?e[X]:null===Object.getPrototypeOf(e)?"nullobject":J;return"object"!==t?t:F(j,e,"configurable","enumerable","writable")&&j(e,"value")||F(j,e,"get","set")?"descriptor":t}function T(e,t){if(!t)return E(e);switch(I(t)){case"object":return Object.keys(t).reduce(V,{source:t,target:e}).target;case"array":return t.reduce(U,e);default:return e}}function U(e,t,n){return e[n]=y(e,n)?I(e[n])==I(t)?T(e[n],t):e[n]:E(t),e}function V(e,t){return e.target[t]=y(e.target,t)?I(e.target[t])==I(e.source[t])?T(e.target[t],e.source[t]):e.target[t]:E(e.source[t]),e}function W(){return dt.call(arguments).forEach(H),r}function G(e){e(this,r)}function H(e){y(e,Y)||f(e,Y,0,"w");var t=yt[e[Q]||d(e)];t&&(t.slice(e[Y]).forEach(G,e),e[Y]=t.length)}"undefined"==typeof global?e:e=global;var J,Q="__name__",X="__type__",Y="__xid__",Z="undefined"!=typeof module&&"exports"in module&&"function"==typeof require?"commonjs":"undefined"!=typeof navigator?"browser":"other",et=Object.prototype,tt="commonjs"!=Z?null:require("module"),nt=[!1,0/0,null,!0,J].reduce(function(e,t){return e[t+""]=t,e},C()),rt="htmlcollection",ut="htmldocument",ot=999,ct="anon",it=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,u){function o(e){r[e]=r[u]}var c=e[u];return r[u]=t.reduce(function(e,t,r){return e[t]=n[u][r],e},C()),!c||(Array.isArray(c)?c.forEach(o):o(c)),r},C());return delete r[J],r}(),at="Array Boolean Date Function Null Number Object RegExp String Undefined".split(" ").reduce(function(e,t){return e["[object "+t+"]"]=t.toLowerCase(),e},C()),ft=Math.random,st=/global|window/i,lt=/\$?\{([^\}]+)\}/g,pt=/[xy]/g,ht=RegExp("^\\u005E?"+t),bt=/[\s\(]*function([^\(]+).*/,gt=/^[Ww]ebkit|[Mm]oz|O|[Mm]s|[Kk]html(.*)$/,dt=Array.prototype.slice,mt="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",yt={Array:[],Boolean:[],Date:[],Function:[],Number:[],Object:[],RegExp:[],String:[]};f(W,"cache",function(e,t){return"string"==typeof e||(e=e[Q]||d(e)),yt[e]||(yt[e]=[]),yt[e].push(t),r},"w"),W.cache("Array",function(e){var t=e.prototype;f(e,"coerce",function(e,t,n){return y(e,"length")?(t="number"==K(t)?t>0?t:0:0,n="number"==K(n)?n>t?n:0>=n?e.length+n:t+n:e.length,dt.call(e,t,n)):[e]},"w"),s(t,{find:function(e,t){var n=-1,r=this.length>>>0;for(t||(t=this);r>++n;)if(e.call(t,this[n],n,this))return this[n];return null},invoke:function(n){var r=e.coerce(arguments,1);return t.map.call(this,function(e){return e&&"function"==typeof e[n]?e[n].apply(e,r):J})},pluck:function(e,n){return n=n===!0,t.reduce.call(this,function(t,r){var u=Object.value(r,e);return n&&!b(u)||t.push(u),t},[])}},"w")}),W.cache("Boolean",function(e){f(e,"coerce",function(e){switch(K(e)){case"boolean":return e;case"nan":case!1:return!1;case"number":case"string":return!(e in nt?!nt[e]:0===Number(e))}return!0},"w")}),W.cache("Function",function(e){function t(e){return!e||e in o}function n(){return""+this}function r(){return this}var u="__xname__",o={Anonymous:!0,anonymous:!0},c={mimic:function(e,t){var u=e.valueOf();return s(this,{displayName:t||d(u),toString:n.bind(u),valueOf:r.bind(u)},"c",!0),this}};c[Q]={get:function(){if(!this[u]){var e=this.valueOf(),n=e!==this?t(e[Q])?null:e[Q]:null,r=n||d(this);!t(r)||t(this.displayName)||(r=this.displayName),f(this,u,r||"anonymous","w")}return this[u]}},s(e.prototype,c,"w"),f(e,"anon_list",{value:o},"w")}),W.cache("Object",function(e){f(e.prototype,X,i({get:function(){var e,t=this,n=t.constructor,r=I(t),u=z(r)||(st.test(r)?"global":!1);return u?u:"number"==r?isNaN(t)?"nan":"number":"object"==r&&"function"==typeof n&&"function"!=n[X]?(e=(n[Q]+"").toLowerCase(),e&&"anonymous"!=e?e:n[X]||r):r}},it.r)),f(e.prototype,"__proto__",{get:function(){return e.getPrototypeOf(this)}},"c"),s(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,u){return e=n.call(t,e,t[r],r,t,u)},r)},value:function(t,n){if(isNaN(n)){if(y(t,n))return t[n];if(~n.indexOf(".")){var r;for(n=n.split(".");(r=n.shift())&&(t=e.value(t,r))!==J;);return t}}return h(t)?J:b(t[n])?t[n]:"function"==typeof t.get?t.get(n):"function"==typeof t.getAttribute?t.getAttribute(n):J},values:function(t){return e.keys(Object(t)).map(function(e){return t[e]})}},"w")}),k(n)||(n="commonjs"==Z?module:e),s(r=g(r,t,n),{ENV:Z,global:{value:e},modes:{value:it},bless:u,coerce:c,copy:i,cpdef:a,def:f,defs:s,describe:l,description:p,empty:h,exists:b,expose:g,format:m,got:F.bind(null,y),gsub:w,guid:x,has:F.bind(null,j),id:O,iter:k,len:A,merge:E,nativeType:I,noop:B,ntype:I,obj:C,range:L,remove:D,tostr:$,type:K,update:T,valof:q,x:W},"w"),W(Object,Array,Boolean,Function)}(this,"m8");
+!function(e,t,n){"use strict";function r(e){return e}function u(e,t){switch(K(e)){case"array":break;case"string":e=e.split(".");break;default:return i(t)}if(dt.test(e[0])&&(t=r,e.shift()),!e.length)return i(t);e[0].indexOf("^")||(t||"^"==e[0]?e.shift():e[0]=e[0].substring(1)),t=i(t);for(var n;n=e.shift();)t=t[n]||(t[n]=D());return t}function i(t){return"commonjs"==tt?t?k(t)?t.exports:t:module.exports:t||e}function o(e){var t,n=Number(e);return isNaN(n)?(t=e+"")in ut?ut[t]:e:n}function c(e,t,n){n=n===!0,t||(t=e,e=D());for(var r in t)!O(t,r)||n&&O(e,r)||(e[r]=t[r]);return e}function a(e,t,n){return n=n===!0,t||(t=e,e=D()),Object.getOwnPropertyNames(t).reduce(function(e,r){return n&&O(e,r)||f(e,r,h(t,r)),e},e)}function f(e,n,u){var i,o,c,a,f=mt.call(arguments,3),s=w(e,n);switch(K(f[0])){case"string":o=ft[f.shift()];break;case"object":o=f.shift();break;default:c=K(u),o="object"!=c&&s?h(e,n):null,!o||(o="function"==c?ft.cw:ft.cew)}return a=f.shift()===!0,i=f.shift()===!0,s&&!a?i&&Error(t+".def cannot overwrite existing property: "+n+", in item type: "+T(e)+"."):("object"!=c&&o&&(u=p(u,o)),(u.get||u.set)&&delete u.writable,Object.defineProperty(e,n,u)),r}function s(e,t,n){return et?("array"!=K(t)&&(n=t,t=[]),define(e,t,function(){return n}),r):void 0}function l(e,t,n,u,i){n||(n="cw");for(var o in t)!O(t,o)||f(e,o,t[o],n,u,i);return r}function p(e,t){return c("object"==K(e)?e:{value:e},"object"==K(t)?t:ft[(t+"").toLowerCase()]||ft.cew,!0)}function h(e,t){return Object.getOwnPropertyDescriptor(e,t)}function b(e){return!d(e)||!E(e)&&A(e)||!1}function d(e){return!(null===e||e===Q||"number"==typeof e&&isNaN(e))}function g(t,n,r){"string"!=typeof n&&t[X]&&(r=n,n=t[X]);var u,i=D();return i[X]=n,i[Y]="library","commonjs"==tt&&k(r)?r.exports=t:(r||(r=e),(u=r[n])&&A(u)?(u[n]=t,t=a(u,t)):f(r,n,p({value:t},"ew")),!et||r!==e||s(n,t)),l(t,i,"w",!0),t}function y(e){return e.name||e.displayName||((e+"").match(gt)||["",""])[1].trim()}function m(e){return x(e,Array.coerce(arguments,1))}function w(e,t){return t+""in Object(e)}function x(e,t,n){return(e+"").replace(n||ht,function(e,n){return t[n]||""})}function v(){return wt.replace(bt,j)}function j(e){var t=0|16*lt();return("x"==e?t:8|3&t).toString(16)}function O(e,t){return nt.hasOwnProperty.call(Object(e),t+"")}function N(e,t){return e?w(e,"id")&&!b(e.id)?e.id:e.id=_(t):_(t)}function _(e){return(e||at)+"-"+ ++ct}function k(e){if(null===rt)return!1;try{return e instanceof rt}catch(t){return!1}}function A(e){return w(e,"length")||"object"==K(e)}function E(e){return("length"in(e=Object(e))?e:Object.keys(e)).length}function P(e,t){var n;if(t)n=K(t);else switch(n=K(e)){case"array":case"object":t=e,e=new(t.constructor||Object);break;default:return e}switch(n){case"object":return Object.keys(t).reduce(B,{source:t,target:e}).target;case"array":return e.length=t.length,t.reduce(S,e);default:return t}}function S(e,t,n){return e[n]=K(e[n])===K(t)?P(e[n],t):P(t),e}function B(e,t){return e.target[t]=K(e.target[t])===K(e.source[t])?P(e.target[t],e.source[t]):P(e.source[t]),e}function C(){}function D(e){var t=Object.create(null);return"object"==typeof e?c(t,e):t}function F(e,t,n){var r;if(n+="",arguments.length>3){for(n=mt.call(arguments,2);r=n.shift();)if(F(e,t,r))return!0;return!1}if(e(t,n))return!0;if("string"!=typeof t&&~n.indexOf(".")){for(n=n.split(".");r=n.shift();){if(!F(e,t,r))return!1;t=t[r]}return!0}return!1}function L(e,t){for(var n=[e];t>=++e;)n.push(e);return n}function M(e,t){t=Array.isArray(t)?t:mt.call(arguments,1);var n=Array.isArray(e)?R:$;return t.forEach(n,e),e}function R(e){var t=this.indexOf(e);t=~t?t:!isNaN(e)&&e in this?e:t,0>t||this.splice(t,1)}function $(e){delete this[e]}function q(e){return nt.toString.call(e)}function z(e){return nt.valueOf.call(e)}function I(e){return e==ot?ot:e==it||"nodelist"==e?it:e.indexOf("htm")||e.lastIndexOf("element")+7!==e.length?!1:"htmlelement"}function K(e){var t=q(e);return t in st?st[t]:st[t]=t.split(" ")[1].split("]")[0].replace(yt,"$1").toLowerCase()}function T(e){if(null===e||e===Q)return!1;var t=w(e,Y)?e[Y]:null===Object.getPrototypeOf(e)?"nullobject":Q;return"object"!==t?t:F(O,e,"configurable","enumerable","writable")&&O(e,"value")||F(O,e,"get","set")?"descriptor":t}function U(e,t){if(!t)return P(e);switch(K(t)){case"object":return Object.keys(t).reduce(W,{source:t,target:e}).target;case"array":return t.reduce(V,e);default:return e}}function V(e,t,n){return e[n]=w(e,n)?K(e[n])==K(t)?U(e[n],t):e[n]:P(t),e}function W(e,t){return e.target[t]=w(e.target,t)?K(e.target[t])==K(e.source[t])?U(e.target[t],e.source[t]):e.target[t]:P(e.source[t]),e}function G(){return mt.call(arguments).forEach(J),r}function H(e){e(this,r)}function J(e){w(e,Z)||f(e,Z,0,"w");var t=xt[e[X]||y(e)];t&&(t.slice(e[Z]).forEach(H,e),e[Z]=t.length)}"undefined"==typeof global?e:e=global;var Q,X="__name__",Y="__type__",Z="__xid__",et="function"==typeof define&&define.amd,tt="undefined"!=typeof module&&"exports"in module&&"function"==typeof require?"commonjs":"undefined"!=typeof navigator?"browser":"other",nt=Object.prototype,rt="commonjs"!=tt?null:require("module"),ut=[!1,0/0,null,!0,Q].reduce(function(e,t){return e[t+""]=t,e},D()),it="htmlcollection",ot="htmldocument",ct=999,at="anon",ft=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,u){function i(e){r[e]=r[u]}var o=e[u];return r[u]=t.reduce(function(e,t,r){return e[t]=n[u][r],e},D()),!o||(Array.isArray(o)?o.forEach(i):i(o)),r},D());return delete r[Q],r}(),st="Array Boolean Date Function Null Number Object RegExp String Undefined".split(" ").reduce(function(e,t){return e["[object "+t+"]"]=t.toLowerCase(),e},D()),lt=Math.random,pt=/global|window/i,ht=/\$?\{([^\}'"]+)\}/g,bt=/[xy]/g,dt=RegExp("^\\u005E?"+t),gt=/[\s\(]*function([^\(]+).*/,yt=/^[Ww]ebkit|[Mm]oz|O|[Mm]s|[Kk]html(.*)$/,mt=Array.prototype.slice,wt="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",xt={Array:[],Boolean:[],Date:[],Function:[],Number:[],Object:[],RegExp:[],String:[]};f(G,"cache",function(e,t){return"string"==typeof e||(e=e[X]||y(e)),xt[e]||(xt[e]=[]),xt[e].push(t),r},"w"),G.cache("Array",function(e){var t=e.prototype;f(e,"coerce",function(e,t,n){return w(e,"length")?(t="number"==T(t)?t>0?t:0:0,n="number"==T(n)?n>t?n:0>=n?e.length+n:t+n:e.length,mt.call(e,t,n)):[e]},"w"),l(t,{find:function(e,t){var n=-1,r=this.length>>>0;for(t||(t=this);r>++n;)if(e.call(t,this[n],n,this))return this[n];return null},invoke:function(n){var r=e.coerce(arguments,1);return t.map.call(this,function(e){return e&&"function"==typeof e[n]?e[n].apply(e,r):Q})},pluck:function(e,n){return n=n===!0,t.reduce.call(this,function(t,r){var u=Object.value(r,e);return n&&!d(u)||t.push(u),t},[])}},"w")}),G.cache("Boolean",function(e){f(e,"coerce",function(e){switch(T(e)){case"boolean":return e;case"nan":case!1:return!1;case"number":case"string":return!(e in ut?!ut[e]:0===Number(e))}return!0},"w")}),G.cache("Function",function(e){function t(e){return!e||e in i}function n(){return""+this}function r(){return this}var u="__xname__",i={Anonymous:!0,anonymous:!0},o={mimic:function(e,t){var u=e.valueOf();return l(this,{displayName:t||y(u),toString:n.bind(u),valueOf:r.bind(u)},"c",!0),this}};o[X]={get:function(){if(!this[u]){var e=this.valueOf(),n=e!==this?t(e[X])?null:e[X]:null,r=n||y(this);!t(r)||t(this.displayName)||(r=this.displayName),f(this,u,r||"anonymous","w")}return this[u]}},l(e.prototype,o,"w"),f(e,"anon_list",{value:i},"w")}),G.cache("Object",function(e){f(e.prototype,Y,c({get:function(){var e,t=this,n=t.constructor,r=K(t),u=I(r)||(pt.test(r)?"global":!1);return u?u:"number"==r?isNaN(t)?"nan":"number":"object"==r&&"function"==typeof n&&"function"!=n[Y]?(e=(n[X]+"").toLowerCase(),e&&"anonymous"!=e?e:n[Y]||r):r}},ft.r)),f(e.prototype,"__proto__",{get:function(){return e.getPrototypeOf(this)}},"c"),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,u){return e=n.call(t,e,t[r],r,t,u)},r)},value:function(t,n){if(isNaN(n)){if(w(t,n))return t[n];if(~n.indexOf(".")){var r;for(n=n.split(".");(r=n.shift())&&(t=e.value(t,r))!==Q;);return t}}return b(t)?Q:d(t[n])?t[n]:"function"==typeof t.get?t.get(n):"function"==typeof t.getAttribute?t.getAttribute(n):Q},values:function(t){return e.keys(Object(t)).map(function(e){return t[e]})}},"w")}),A(n)||(n="commonjs"==tt?module:e),l(r=g(r,t,n),{AMD:et,ENV:tt,global:{value:e},modes:{value:ft},bless:u,coerce:o,copy:c,cpdef:a,def:f,defs:l,define:s,describe:p,description:h,empty:b,exists:d,expose:g,format:m,got:F.bind(null,w),gsub:x,guid:v,has:F.bind(null,O),id:N,iter:A,len:E,merge:P,nativeType:K,noop:C,ntype:K,obj:D,range:L,remove:M,tostr:q,type:T,update:U,valof:z,x:G},"w"),G(Object,Array,Boolean,Function)}(this,"m8");
View
2  package.json
@@ -27,5 +27,5 @@
"scripts" : {
"test" : "mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"
},
- "version" : "0.3.6"
+ "version" : "0.3.7"
}
View
32 src/expose.js
@@ -2,23 +2,23 @@
defs( ( __lib__ = expose( __lib__, Name, PACKAGE ) ), {
// properties
- ENV : ENV, global : { value : root },
- modes : { value : modes },
+ AMD : AMD, ENV : ENV,
+ global : { value : root }, modes : { value : modes },
// methods
- bless : bless, coerce : coerce,
- copy : copy, cpdef : cpdef,
- def : def, defs : defs,
- describe : describe, description : description,
- empty : empty, exists : exists,
- expose : expose, format : format, got : prop_exists.bind( null, got ),
- gsub : gsub, guid : guid, has : prop_exists.bind( null, has ),
- id : id, iter : iter,
- len : len, merge : merge,
- nativeType : nativeType, noop : noop,
- ntype : nativeType, obj : obj,
- range : range, remove : remove,
- tostr : tostr, type : type,
- update : update, valof : valof,
+ bless : bless, coerce : coerce,
+ copy : copy, cpdef : cpdef,
+ def : def, defs : defs, define : define_amd,
+ describe : describe, description : description,
+ empty : empty, exists : exists,
+ expose : expose, format : format, got : prop_exists.bind( null, got ),
+ gsub : gsub, guid : guid, has : prop_exists.bind( null, has ),
+ id : id, iter : iter,
+ len : len, merge : merge,
+ nativeType : nativeType, noop : noop,
+ ntype : nativeType, obj : obj,
+ range : range, remove : remove,
+ tostr : tostr, type : type,
+ update : update, valof : valof,
x : x
}, 'w' );
View
17 src/lib.js
@@ -71,6 +71,19 @@
return __lib__;
}
+ function define_amd( path, deps, mod ) {
+ if ( !AMD ) return;
+
+ if ( nativeType( deps ) != 'array' ) {
+ mod = deps;
+ deps = [];
+ }
+
+ define( path, deps, function() { return mod; } );
+
+ return __lib__;
+ }
+
function defs( item, props, mode, overwrite, debug ) {
mode || ( mode = 'cw' );
for ( var key in props )
@@ -109,8 +122,8 @@
else
def( mod, name, describe( { value : lib }, 'ew' ) );
- if ( ENV == 'browser' && mod === root ) // don't expose as amd if lib is being added to a module that will be exposed
- typeof define != 'function' || !define.amd || define( name, [], function() { return lib; } );
+ // don't expose as amd if lib is being added to a module that will be exposed
+ !AMD || mod !== root || define_amd( name, lib );
}
defs( lib, defaults, 'w', true );
View
3  src/vars.js
@@ -3,6 +3,7 @@
var __name__ = '__name__', __type__ = '__type__', __xid__ = '__xid__',
// it's a best guess as to whether the environment we're in is a browser, commonjs platform (like nodejs) or something else completely
+ AMD = typeof define == 'function' && define.amd,
ENV = typeof module != 'undefined' && 'exports' in module && typeof require == 'function' ? 'commonjs' : typeof navigator != 'undefined' ? 'browser' : 'other',
OP = Object.prototype, UNDEF,
// this will be used by the bless method to check if a context root is a commonjs module or not.
@@ -46,7 +47,7 @@
return cache;
}, obj() ),
randy = Math.random, re_global = /global|window/i,
- re_gsub = /\$?\{([^\}]+)\}/g, re_guid = /[xy]/g, re_lib = new RegExp( '^\\u005E?' + Name ),
+ re_gsub = /\$?\{([^\}'"]+)\}/g, 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, tpl_guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx',
xcache = {
View
1  test/m8.test.js
@@ -165,6 +165,7 @@ suite( 'm8', function() {
test( '<static> m8.format', function( done ) {
expect( m8.format( '{0}, {1}, {2}, {3}, {4}, {5}, {6}, ${7}, ${8}, ${9}', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine' ) ).to.deep.equal( 'zero, one, two, three, four, five, six, seven, eight, nine' );
+ expect( m8.format( '{ "{0}" : \'{1}\', "${2}" : \'${3}\' }', 'zero', 'one', 'two', 'three' ) ).to.deep.equal( '{ "zero" : \'one\', "two" : \'three\' }' );
done();
} );
Please sign in to comment.
Something went wrong with that request. Please try again.