WIP: try to convert to ES modules

This commit is contained in:
j 2026-02-09 18:59:12 +01:00
commit 299a08b6a3
29 changed files with 3003 additions and 2014 deletions

View file

@ -1,5 +1,17 @@
'use strict';
import * as OxObject from './Object.js';
import * as OxConstants from './Constants.js';
import * as OxMath from './Math.js';
const Ox = {};
Object.assign(Ox,
OxObject,
OxConstants,
OxMath
);
/*@
Ox.cache <f> Memoize a function
fn <f> function
@ -15,7 +27,7 @@ Ox.cache <f> Memoize a function
false
@*/
// TODO: add async test
Ox.cache = function(fn, options) {
export function cache(fn, options) {
var cache = {}, ret;
options = options || {};
options.async = options.async || false;
@ -65,7 +77,7 @@ Ox.debounce <f> Runs a function once it stops being called for a given interval
ms <n|250> Interval in milliseconds
immediate <b|false> If true, function is called once immediately
@*/
Ox.debounce = function(fn/*, ms, immediate*/) {
export function debounce(fn/*, ms, immediate*/) {
var args,
immediate = Ox.last(arguments) === true,
ms = Ox.isNumber(arguments[1]) ? arguments[1] : 250,
@ -95,7 +107,7 @@ Ox.identity <f> Returns its first argument
> Ox.identity(Infinity)
Infinity
@*/
Ox.identity = function(value) {
export function identity(value) {
return value;
};
@ -108,7 +120,7 @@ Ox.noop <f> Returns undefined and calls optional callback without arguments
> Ox.noop(1, 2, 3, function() { Ox.test(arguments.length, 0); })
undefined
@*/
Ox.noop = function() {
export function noop() {
var callback = Ox.last(arguments);
Ox.isFunction(callback) && callback();
};
@ -118,7 +130,7 @@ Ox.once <f> Runs a function once, and then never again
(fn) -> <f> Function that will run only once
fn <f> Function to run once
@*/
Ox.once = function(fn) {
export function once(fn) {
var once = false;
return function() {
if (!once) {
@ -139,11 +151,11 @@ Ox.queue <f> Queue of asynchronous function calls with cached results
fn <f> Queued function
maxThreads <n|10> Number of parallel function calls
@*/
Ox.queue = function(fn, maxThreads) {
export function queue(fn, maxThreads) {
maxThreads = maxThreads || 10;
var processing = [],
queued = [],
ret = Ox.cache(function() {
ret = cache(function() {
var args = Ox.slice(arguments);
queued.push({args: args, key: getKey(args)});
process();
@ -199,7 +211,7 @@ Ox.throttle <f> Runs a function at most once per given interval
fn <f> Function to throttle
ms <n|250> Interval in milliseconds
@*/
Ox.throttle = function(fn, ms) {
export function throttle(fn, ms) {
var args,
timeout;
ms = arguments.length == 1 ? 250 : ms;
@ -222,7 +234,7 @@ Ox.throttle = function(fn, ms) {
Ox.time <f> Returns the time it takes to execute a given function
(fn) -> <n> Time in milliseconds
@*/
Ox.time = function(fn) {
export function time(fn) {
var time = new Date();
fn();
return new Date() - time;