@rjfwhite/random-lib
v0.0.7
Published
Core engine for MML
Downloads
6
Maintainers
Readme
AingineLib
A TypeScript library that builds to a self-contained ES module for browser usage.
Setup
- Install dependencies:
npm install- Build the library:
npm run buildThis creates a bundled ES module at dist/index.js that can be included in any webpage.
Usage
In HTML with ES Modules
<script type="module">
import AingineLib from './dist/index.js';
const lib = new AingineLib({ debug: true });
console.log(lib.greet('World'));
</script>With Query Parameters
You can pass configuration via query parameters in the script src:
<script type="module">
import AingineLib, { getModuleParam } from './dist/index.js?foo=bar&debug=true&theme=dark';
const lib = new AingineLib();
// Extract query parameters
console.log(lib.getQueryParam('foo')); // 'bar'
console.log(lib.getQueryParam('debug')); // 'true'
console.log(lib.getQueryParams()); // { foo: 'bar', debug: 'true', theme: 'dark' }
// Or use standalone functions
console.log(getModuleParam('theme')); // 'dark'
</script>As a Package
import AingineLib from 'aingine-lib';
const lib = new AingineLib({
debug: true,
theme: 'dark'
});
// Use the library
console.log(lib.greet('Developer'));
const button = lib.createButton('Click me!', () => alert('Clicked!'));
document.body.appendChild(button);Development
npm run build- Build production bundle (minified)npm run build:dev- Build with watch mode for developmentnpm run build:types- Generate TypeScript declaration filesnpm run build:all- Build both bundle and typesnpm run dev- Start development mode with watchnpm run clean- Clean dist foldernpm run serve- Start HTTP server on port 3000npm run start- Build and start servernpm run demo- Build, start server, and open browser
Features
- ✅ Self-contained ES module bundle
- ✅ TypeScript support with type declarations
- ✅ Minified production build
- ✅ Source maps for debugging
- ✅ Fast builds with esbuild
- ✅ Works directly in browsers with
<script type="module"> - ✅ Query parameter extraction from module URL
Query Parameter API
The library provides several ways to extract query parameters from the module URL:
Standalone Functions
import { getModuleParam, getModuleParamsObject, getModuleQueryParams } from './dist/index.js?foo=bar&debug=true';
// Get a specific parameter
const foo = getModuleParam('foo'); // 'bar'
// Get all parameters as an object
const allParams = getModuleParamsObject(); // { foo: 'bar', debug: 'true' }
// Get raw URLSearchParams object
const params = getModuleQueryParams(); // URLSearchParams instanceInstance Methods
import AingineLib from './dist/index.js?user=john&config=prod';
const lib = new AingineLib();
// Get a specific parameter
lib.getQueryParam('user'); // 'john'
// Get all parameters
lib.getQueryParams(); // { user: 'john', config: 'prod' }
// Check if parameter exists
lib.hasQueryParam('user'); // true
lib.hasQueryParam('missing'); // falseBrowser Support
The generated ES module works in all modern browsers that support ES modules:
- Chrome 61+
- Firefox 60+
- Safari 10.1+
- Edge 16+
