Skip to content

alexstevovich/link-tote-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

link-tote

Canonical URL:
https://alexstevovich.com/a/link-tote-nodejs

Software URL:
https://midnightcitylights.com/software/link-tote-nodejs

A small and flexible link catalog for Node.js — ideal for managing platform links, external URLs, and references within a site or project.
link-tote supports loading, filtering, and removing entries directly from JSON files.


Installation

npm install link-tote

Example

import LinkTote from 'link-tote';

// Initialize with data
const tote = new LinkTote([
    {
        id: 'github',
        name: 'GitHub',
        url: 'https://github.com/example',
        type: 'dev',
        tags: ['external'],
    },
    {
        id: 'studio',
        name: 'Example Studio',
        url: 'https://studio.example.com',
        type: 'brand',
        tags: ['owned'],
    },
]);

console.log(tote.getById('github'));
console.log(tote.getAllByType('dev'));
console.log(tote.getAllByTag('owned'));

Example JSON file for loading

[
    {
        "id": "github",
        "name": "GitHub",
        "url": "https://github.com/example",
        "type": "dev",
        "tags": ["external"]
    },
    {
        "id": "studio",
        "name": "Example Studio",
        "url": "https://studio.example.com",
        "type": "brand",
        "tags": ["owned"]
    }
]

Load from File

await tote.loadFromFile('./data/links.json');

Methods

load(entries)

Appends or loads multiple entries into the catalog.
Automatically normalizes missing types and wraps single string tags in an array.

loadFromFile(filePath)

Asynchronously loads entries from a JSON file (expects an array of objects).
Logs an error if the file cannot be read or is invalid.

getAll()

Returns all entries in the catalog.

getById(id)

Retrieves a single entry by its ID. Returns null if not found.

removeById(id)

Removes an entry by ID.

getAllByTag(tagOrTags)

Returns all entries containing one or more specified tags.

removeByTag(tag)

Removes all entries containing a specific tag.

removeMatchingUrls(list)

Removes entries whose url matches any entry in a given list of objects (expects url fields).

License

Licensed under the Apache License 2.0.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published