script-tote
v1.0.0
Published
Unified registry and loader for JavaScript file metadata used across site frameworks
Maintainers
Readme
script-tote
Canonical URL:
https://alexstevovich.com/a/script-tote-nodejs
Software URL:
https://midnightcitylights.com/software/script-tote-nodejs
A utility that collects, indexes, and manages metadata for JavaScript files across a project.
Useful for site-wide resource management, build automation, and HTML generation systems.
Installation
npm install script-toteExample
import ScriptTote from 'script-tote';
const tote = new ScriptTote();
// Manually add entries
tote.add({
src: '/js/main.js',
module: true,
loading: 'defer',
tags: ['core', 'ui'],
});
// Automatically load all `.js` files from a folder
tote.loadFromNestedDir('./public', './public/js', {
module: true,
loading: 'defer',
tags: ['site'],
});
// Access data
console.log(tote.getAll());
console.log(tote.getById('/js/main.js'));
console.log(tote.getByTags('core'));Example Output
[
{
"id": "/js/main.js",
"src": "/js/main.js",
"module": true,
"loading": "defer",
"tags": ["core", "ui"]
}
]Methods
add(entries)
Adds one or more script entries.
Each entry supports:
| Key | Type | Default | Description |
| --------- | ---------- | --------- | ------------------------------------------------ |
| id | string | src | Unique identifier. |
| src | string | — | Path to the JavaScript file. |
| module | boolean | true | Whether to treat it as an ES module. |
| loading | string | "defer" | Loading attribute (e.g. "defer" or "async"). |
| tags | string[] | [] | Arbitrary category tags. |
loadFromNestedDir(rootDir, nestedDir, opts)
Scans a directory for .js files and adds them with metadata.
| Option | Type | Default | Description |
| ----------- | ---------- | --------- | ---------------------------------------- |
| recursive | boolean | false | Scan subfolders recursively. |
| module | boolean | true | Add files as ES modules. |
| loading | string | "defer" | Loading strategy used in generated tags. |
| tags | string[] | [] | Tag list for added entries. |
Retrieval and Filtering
getAll()→ Returns all entries.getById(id)→ Returns a single entry by ID.getByTags(tags)→ Returns entries matching any tag(s).removeById(id)→ Deletes an entry by ID.removeByTag(tag)→ Deletes all entries with the given tag.
License
Licensed under the Apache License 2.0.
