WIP: use es-modules
This commit is contained in:
parent
ec5b050496
commit
baef49f116
143 changed files with 738 additions and 55 deletions
|
|
@ -1,5 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.api <f> Turns an array into a list API
|
||||
`Ox.api` takes an array and returns a function that allows you to run
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
(function() {
|
||||
|
||||
function asyncMap(forEach, collection, iterator, that, callback) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.avg <f> Returns the average of an array's values, or an object's properties
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.hsl <f> Takes RGB values and returns HSL values
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
//@ Ox.AMPM <[s]> ['AM', 'PM']
|
||||
Ox.AMPM = ['AM', 'PM'];
|
||||
|
|
@ -101,6 +102,8 @@ Ox.PATH = (function() {
|
|||
return src.replace(regexp, '');
|
||||
}
|
||||
}
|
||||
// FIXME: fix path detection
|
||||
return './source/';
|
||||
}());
|
||||
//@ Ox.MODE <s> Mode ('dev' or 'min')
|
||||
Ox.MODE = Ox.PATH.slice(0, -1).split('/').pop();
|
||||
|
|
|
|||
|
|
@ -2,15 +2,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
/*@
|
||||
Ox <f> The `Ox` object
|
||||
See `Ox.wrap` for details.
|
||||
(value) -> <o> wrapped value
|
||||
value <*> Any value
|
||||
@*/
|
||||
this.Ox = function(value) {
|
||||
return Ox.wrap(value);
|
||||
};
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.load <f> Loads OxJS and, optionally, one or more modules
|
||||
|
|
@ -76,20 +68,17 @@ Ox.load = function() {
|
|||
if (!length) {
|
||||
callback(true);
|
||||
} else {
|
||||
Ox.forEach(modules, function(options, module) {
|
||||
Ox.getFile(
|
||||
Ox.PATH + module + '/' + module + '.js?' + Ox.VERSION,
|
||||
function() {
|
||||
Ox.load[module](options, function(success) {
|
||||
succeeded += success;
|
||||
if (++loaded == length) {
|
||||
Ox.setLocale(Ox.LOCALE, function() {
|
||||
callback(succeeded == length);
|
||||
});
|
||||
}
|
||||
Ox.forEach(modules, async function(options, module) {
|
||||
console.log("load module!", module, options)
|
||||
const obj = await import('../../' + module + '/index.js?' + Ox.VERSION);
|
||||
Ox.load[module](options, function(success) {
|
||||
succeeded += success;
|
||||
if (++loaded == length) {
|
||||
Ox.setLocale(Ox.LOCALE, function() {
|
||||
callback(succeeded == length);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -114,7 +103,7 @@ Ox.localStorage = function(namespace) {
|
|||
var localStorage;
|
||||
try {
|
||||
// this will fail if third party cookies/storage is not allowed
|
||||
localStorage = window.localStorage || {};
|
||||
localStorage = globalThis.localStorage || {};
|
||||
// FF 3.6 can't assign to or iterate over localStorage
|
||||
for (var key in localStorage) {}
|
||||
// In Safari (OS X or iOS) is in private browsing mode,
|
||||
|
|
@ -206,7 +195,7 @@ Ox.Log = (function() {
|
|||
args.unshift(
|
||||
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().slice(-3)
|
||||
);
|
||||
window.console && window.console.log && window.console.log.apply(window.console, args);
|
||||
globalThis.console && globalThis.console.log && globalThis.console.log.apply(globalThis.console, args);
|
||||
ret = args.join(' ');
|
||||
}
|
||||
return ret;
|
||||
|
|
@ -268,7 +257,7 @@ Ox.print = function() {
|
|||
args.unshift(
|
||||
date.toString().split(' ')[4] + '.' + (+date).toString().slice(-3)
|
||||
);
|
||||
window.console && window.console.log.apply(window.console, args);
|
||||
globalThis.console && globalThis.console.log.apply(globalThis.console, args);
|
||||
return args.join(' ');
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.$ <f> Generic HTML element, mimics jQuery
|
||||
|
|
@ -828,12 +829,12 @@ Ox.documentReady <function> Calls a callback function once the DOM is ready
|
|||
@*/
|
||||
Ox.documentReady = (function() {
|
||||
var callbacks = [];
|
||||
document.onreadystatechange = window.onload = function() {
|
||||
document.onreadystatechange = globalThis.onload = function() {
|
||||
if (document.readyState == 'complete') {
|
||||
callbacks.forEach(function(callback) {
|
||||
callback();
|
||||
});
|
||||
document.onreadystatechange = window.onload = null;
|
||||
document.onreadystatechange = globalThis.onload = null;
|
||||
}
|
||||
};
|
||||
return function(callback) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
//@ Ox.getDate <f> Get the day of a date, optionally UTC
|
||||
// see Ox.setSeconds for source code
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.encodeBase26 <b> Encode a number as bijective base26
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.formatArea <f> Formats a number of meters as square meters or kilometers
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.cache <f> Memoize a function
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
(function() {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
(function() {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.oshash <f> Calculates oshash for a given file or blob object. Async.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.doc <f> Generates documentation for annotated JavaScript
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
(function() {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.acosh <f> Inverse hyperbolic cosine
|
||||
|
|
|
|||
14
source/Ox/js/Namespace.js
Normal file
14
source/Ox/js/Namespace.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
/*@
|
||||
Ox <f> The `Ox` object
|
||||
See `Ox.wrap` for details.
|
||||
(value) -> <o> wrapped value
|
||||
value <*> Any value
|
||||
@*/
|
||||
export const Ox = function(value) {
|
||||
return Ox.wrap(value)
|
||||
};
|
||||
|
||||
export default Ox;
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.extend <function> Extends an object with one or more other objects
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
(function(window) {
|
||||
|
||||
|
|
@ -427,4 +428,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
}(this));
|
||||
}(globalThis));
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.escapeRegExp <f> Escapes a string for use in a regular expression
|
||||
(str) -> <r> Escaped string
|
||||
|
|
@ -10,4 +12,4 @@ Ox.escapeRegExp <f> Escapes a string for use in a regular expression
|
|||
// see https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions
|
||||
Ox.escapeRegExp = function(string) {
|
||||
return (string + '').replace(/([\/\\^$*+?.\-|(){}[\]])/g, '\\$1');
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.get <f> Get a remote resource
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.char <f> Alias for String.fromCharCode
|
||||
|
|
@ -265,17 +266,30 @@ Ox.parseURL <f> Takes a URL, returns its components
|
|||
'?a=0&b=1'
|
||||
@*/
|
||||
Ox.parseURL = (function() {
|
||||
var a = document.createElement('a'),
|
||||
keys = ['hash', 'host', 'hostname', 'origin',
|
||||
'pathname', 'port', 'protocol', 'search'];
|
||||
return function(string) {
|
||||
var ret = {};
|
||||
a.href = string;
|
||||
keys.forEach(function(key) {
|
||||
ret[key] = a[key];
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
const keys = [
|
||||
'hash', 'host', 'hostname', 'origin',
|
||||
'pathname', 'port', 'protocol', 'search'
|
||||
];
|
||||
if (typeof document == 'undefined') {
|
||||
return function(string) {
|
||||
const a = new URL(string);
|
||||
var ret = {};
|
||||
keys.forEach(function(key) {
|
||||
ret[key] = a[key];
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
var a = document.createElement('a');
|
||||
return function(string) {
|
||||
var ret = {};
|
||||
a.href = string;
|
||||
keys.forEach(function(key) {
|
||||
ret[key] = a[key];
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
||||
// FIXME: can we get rid of this?
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.checkType <f> Throws a TypeError if a value is not of a given type
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
import Ox from './Namespace.js';
|
||||
|
||||
/*@
|
||||
Ox.getVideoFormat <f> Get supported video format
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue