@l8js/l8

0.12.1 • Public • Published

@l8js/l8 MIT npm version build

l8.js (Read: light js)

Site | Twitter

Lightweight JavaScript library.
Skipping bold abstraction layers for the sake of a more lean approach towards functional programming.

l8js is released under the MIT license & supports modern environments.

Why l8.js?

l8.js provides functionality, wrappers and thin(!) abstraction layers to ease the process of accessing and manipulating data in JavaScript. It also provides syntactical sugar for convenient access to language specific functions.

    
    // create object based on null object
    let obj = l8.obj();
    obj.key = "value";
    obj instanceof Object; // false

    // l8.chain
    let obj = {};
    l8.chain("a.b.c.d", obj, "foo"); // obj is { a : { b : {c : { d : "foo"}}}}
    
    
    // l8.visit
    let visitor = (value, path) => {
        return `${path.join(".")}=${value}`;
    };
    let tree = {
        node : {
            node_1 : "a"
        }
    };
    tree = l8.visit(tree, visitor);
    expect(tree.node.node_1).toBe("node.node_1=a");


    // l8.replace
    let str = l8.replace(["foo", "bar"], ["oof", "rab"], "this foo is bar"); // this oof is rab
    str = l8.replace(["A", "B"], ["B", "D"], "A"); // D
    str = l8.replace(["A", "C"], "B", "AC"); // BB
    str = l8.replace(["A", "C"], ["B"], "AC"); // B
    str = l8.replace("A", "B", "A"); // B    
    
    
    // l8.unify
    let str = l8.unify("https:///HOST///api/endpoint//", "/", "://");
    console.log(str); // https://HOST/api/endpoint/"
    
    
    // l8.groupIndices
    var list   = ['4', 5, '1', '3', 6, '8'];
    l8.groupIndices(list); // [[1], [3, 4, 5, 6], [8]]
    
    
    // l8.liquify - fluent async interfaces with the liquify proxy  
    const source = {
        foo : async function () { return this; },
        bar : async function () { return this; },
        snafu : async function () { return "snafu"; }
    };
    await l8.liquify(source).foo().bar().snafu();
    
    
    // l8.load
    const text = await l8.load("./README.md");
    console.log(res); // response text


    // l8.ping - sends HEAD to resource
    const exists = await l8.ping("./README.md");
    console.log(exists); // true or false
    

    // l8.text.toHyperlink - l8.text provides parser-/transformation-utilities 
    const html = l8.text.toHyperlink("This is an url https://www.conjoon.org and it is not clickable");
    console.log(html); // This is an url <a href="https://www.conjoon.org">https://www.conjoon.org</a> and it is not clickable

    
    // l8.template.esix.StringTemplate - Template Engine supporting ES6 Templates-Strings.
    let tpl = l8.template.esix.make("This is a ${templated} string ${that.supports} JavaScript TemplateStrings");
    console.log(tpl.render({templated : "parsed", that : {supports : "that supports"}}));
    // This is a parsed string that supports JavaScript TemplateStrings

    // l8.md5() - create MD5-Hash from String
    let hashed = l8.md5("demo@conjoon.org")
    
    let name = l8.text.nameToOrdinal("New Folder", ["New Folder (1)", "users", "randomName"]);
    console.log(name); // "New Folder (2)"
    
    // ... and many more

Installation

Using npm:

$ npm i @l8js/l8

Running Tests and using Build Scripts

$ npm run build:dev

for installing dev-dependencies. This allows for running tests and build-scripts. The script will also install necessary git hooks.

Usage

Builds can be found in ./dist/. API docs are available in ./docs.
Note: Minimized and none-minimized builds are available. None-minimized can be identified by ".debug." in their file-name (e.g. sourcefile.debug.js vs sourcefile.js).

Module Formats

Default JS Module export

Provides default JS-Module export for the whole l8.js-library.

import l8 from "./dist/l8.runtime.esm.js";

Named JS module exports

Provides named JS-Module exports for the main-packages of l8.js-library.

import {core, template, text} from "./dist/l8.packages.esm.js";

Universal Module Definition (UMD)

Provides a Universal Module Definition for the whole l8.js-library.

<script type="text/javascript" src="./dist/l8.runtime.umd.js" />

3rd-party Acknowledgements

l8.js uses crypto-js for l8.md5().

Readme

Keywords

Package Sidebar

Install

npm i @l8js/l8

Weekly Downloads

44

Version

0.12.1

License

MIT

Unpacked Size

868 kB

Total Files

65

Last publish

Collaborators

  • thorstensuckow