Begin ES modules migration and modern build infrastructure

This commit lays the foundation for migrating OxJS from its custom module
system to ES modules while maintaining backward compatibility.

Key changes:
- Set up npm project with Vite for modern build tooling
- Created ES module versions of core Ox utilities (Type, Collection, DOM, etc.)
- Implemented compatibility layer for legacy Ox.load() pattern
- Added Vitest for testing with initial test suite
- Created script to extract existing inline tests from documentation
- Updated .gitignore for Node.js/npm development

The migration preserves OxJS's innovative inline test system and maintains
backward compatibility. Original source files remain unchanged.

Next steps include migrating UI modules, replacing the Python build script,
and creating npm package distribution.

🤖 Generated with AI assistance
This commit is contained in:
Sanjay Bhangar 2026-02-09 17:17:52 +05:30
commit 4c880728dc
16 changed files with 7465 additions and 12 deletions

80
test/basic.test.js Normal file
View file

@ -0,0 +1,80 @@
import { describe, it, expect, beforeAll } from 'vitest';
import * as Type from '../src/ox/core/Type.js';
import * as Collection from '../src/ox/core/Collection.js';
describe('Basic ES Module Tests', () => {
describe('Type utilities', () => {
it('should correctly identify types', () => {
expect(Type.typeOf([])).toBe('array');
expect(Type.typeOf({})).toBe('object');
expect(Type.typeOf('test')).toBe('string');
expect(Type.typeOf(123)).toBe('number');
expect(Type.typeOf(true)).toBe('boolean');
expect(Type.typeOf(null)).toBe('null');
expect(Type.typeOf(undefined)).toBe('undefined');
expect(Type.typeOf(new Date())).toBe('date');
expect(Type.typeOf(/test/)).toBe('regexp');
expect(Type.typeOf(NaN)).toBe('nan');
});
it('should check for empty values', () => {
expect(Type.isEmpty([])).toBe(true);
expect(Type.isEmpty({})).toBe(true);
expect(Type.isEmpty('')).toBe(true);
expect(Type.isEmpty(null)).toBe(true);
expect(Type.isEmpty(undefined)).toBe(true);
expect(Type.isEmpty([1])).toBe(false);
expect(Type.isEmpty({a: 1})).toBe(false);
expect(Type.isEmpty('test')).toBe(false);
});
it('should check equality', () => {
expect(Type.isEqual([1, 2, 3], [1, 2, 3])).toBe(true);
expect(Type.isEqual({a: 1, b: 2}, {b: 2, a: 1})).toBe(true);
expect(Type.isEqual(NaN, NaN)).toBe(true);
expect(Type.isEqual([1, 2], [1, 2, 3])).toBe(false);
expect(Type.isEqual({a: 1}, {a: 2})).toBe(false);
});
});
describe('Collection utilities', () => {
it('should iterate over arrays', () => {
const result = [];
Collection.forEach([1, 2, 3], (val, idx) => {
result.push(val * 2);
});
expect(result).toEqual([2, 4, 6]);
});
it('should iterate over objects', () => {
const result = {};
Collection.forEach({a: 1, b: 2, c: 3}, (val, key) => {
result[key] = val * 2;
});
expect(result).toEqual({a: 2, b: 4, c: 6});
});
it('should map over collections', () => {
expect(Collection.map([1, 2, 3], x => x * 2)).toEqual([2, 4, 6]);
expect(Collection.map('abc', x => x.toUpperCase())).toBe('ABC');
});
it('should filter collections', () => {
expect(Collection.filter([1, 2, 3, 4], x => x % 2 === 0)).toEqual([2, 4]);
expect(Collection.filter({a: 1, b: 2, c: 3}, x => x > 1)).toEqual({b: 2, c: 3});
});
it('should extend objects', () => {
const target = {a: 1};
const result = Collection.extend(target, {b: 2}, {c: 3});
expect(result).toEqual({a: 1, b: 2, c: 3});
expect(result).toBe(target); // Should modify in place
});
it('should deep extend objects', () => {
const target = {a: {x: 1}};
const result = Collection.extend(true, target, {a: {y: 2}});
expect(result).toEqual({a: {x: 1, y: 2}});
});
});
});

11
test/setup.js Normal file
View file

@ -0,0 +1,11 @@
/**
* Test setup for OxJS tests
*/
// Polyfill for browser globals in Node environment
if (typeof window === 'undefined') {
global.window = global;
}
// Add any other test setup here
console.log('Test environment setup complete');