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,25 @@
'use strict';
import * as OxCore from './Core.js';
import * as OxFunction from './Function.js';
import * as OxConstants from './Constants.js';
import * as OxCollection from './Collection.js';
import * as OxMath from './Math.js';
import * as OxType from './Type.js';
import * as OxArray from './Array.js';
const Ox = {};
Object.assign(Ox,
OxCore,
OxFunction,
OxConstants,
OxCollection,
OxMath,
OxType,
OxArray,
);
/*@
Ox.extend <function> Extends an object with one or more other objects
> Ox.extend({a: 1, b: 1, c: 1}, {b: 2, c: 2}, {c: 3})
@ -9,10 +29,10 @@ Ox.extend <function> Extends an object with one or more other objects
> Ox.extend({a: 1}, 'b')
{a: 1, b: void 0}
@*/
Ox.extend = function(object) {
export function extend(object) {
var args = Ox.slice(arguments, 1);
if (!Ox.isObject(args[0])) {
args = [Ox.makeObject(args)];
args = [makeObject(args)];
}
Ox.forEach(args, function(arg) {
Ox.forEach(arg, function(value, key) {
@ -62,7 +82,7 @@ Ox.getset <f> Generic getter and setter function
> Ox.test.object.options({foo: "foo", bar: "bar"}).options()
{"key": "val", "foo": "foo", "bar": "bar"}
@*/
Ox.getset = function(object, args, callback, that) {
export function getset(object, args, callback, that) {
var object_ = Ox.clone(object), ret;
if (args.length == 0) {
// []
@ -72,7 +92,7 @@ Ox.getset = function(object, args, callback, that) {
ret = Ox.clone(object[args[0]]);
} else {
// [key, val] or [{key: val, ...}]
args = Ox.makeObject(args);
args = makeObject(args);
object = Ox.extend(object, args);
Ox.forEach(args, function(value, key) {
if (!object_ || !Ox.isEqual(object_[key], value)) {
@ -84,7 +104,7 @@ Ox.getset = function(object, args, callback, that) {
return ret;
};
Ox.hasOwn = function(object, value) {
export function hasOwn(object, value) {
return Object.prototype.hasOwnProperty.call(object, value);
};
@ -93,7 +113,7 @@ Ox.keyOf <f> Equivalent of [].indexOf for objects
> Ox.keyOf({a: 1, b: 2, c: 3}, 1)
'a'
@*/
Ox.keyOf = function(object, value) {
export function keyOf(object, value) {
var key;
Ox.forEach(object, function(v, k) {
if (v === value) {
@ -117,7 +137,7 @@ Ox.makeObject <f> Takes an array and returns an object
> (function() { return Ox.makeObject(arguments); }())
{}
@*/
Ox.makeObject = function(array) {
export function makeObject(array) {
var ret = {};
if (Ox.isObject(array[0])) {
// [{foo: 'bar'}]
@ -134,7 +154,7 @@ Ox.methods <f> Returns a sorted list of all method names of an object
> Ox.methods({a: [], b: false, f: function() {}, n: 0, o: {}, s: ''})
['f']
@*/
Ox.methods = function(object, includePrototype) {
export function methods(object, includePrototype) {
var key, keys;
if (includePrototype) {
keys = [];
@ -158,7 +178,7 @@ Ox.serialize <f> Parses an object into query parameters
> Ox.serialize({a: [1, 2], b: true, n: 1, o: {k: 'v'}, s: 'foo'}, true)
'a=[1,2]&b=true&n=1&o={"k":"v"}&s="foo"'
@*/
Ox.serialize = function(object, isJSON) {
export function serialize(object, isJSON) {
var ret = [];
Ox.forEach(object, function(value, key) {
var value;
@ -184,7 +204,7 @@ Ox.unserialize <f> Parses query parameters into an object
{a: [1, 2], b: true, n: 1.2, o: {k: 'v'}, s1: 'foo', s2: 'bar'}
@*/
Ox.unserialize = function(string, isJSON) {
export function unserialize(string, isJSON) {
var ret = {};
Ox.filter(string.split('&')).forEach(function(value) {
var array = value.split('=');
@ -208,7 +228,7 @@ Ox.zipObject <f> Takes a keys and a values array, returns a new object
> Ox.zipObject(['a', 'b'], [1, 2])
{a: 1, b: 2}
@*/
Ox.zipObject = function(keys, values) {
export function zipObject(keys, values) {
var object = {};
keys = Ox.makeArray(keys);
values = Ox.makeArray(values);