Lightweight core library for JavaScript projects
npm install @l8js/l8#### l8.js (_Read: light js_)
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.
``javascript
// 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 https://www.conjoon.org 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
`
Using npm:
`shell`
$ npm i @l8js/l8
#### Running Tests and using Build Scripts
`shell`
$ npm run build:dev
for installing dev-dependencies. This allows for running tests and build-scripts. The script will also
install necessary git hooks.
. 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).$3
#### Default JS Module export
Provides default JS-Module export for the whole l8.js-library.`javascript
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.
`javascript
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.
`html
`3rd-party Acknowledgements
l8.js uses crypto-js for l8.md5()`.