Skip to content

Latest commit

 

History

History
148 lines (114 loc) · 3.93 KB

README.md

File metadata and controls

148 lines (114 loc) · 3.93 KB

Utils

version Maintenance MIT dep size Known Vulnerabilities Build Status

SlimIO Utils. This package has been created for internal usage (Features are added to the package to avoid spreading of similar functionalities across multiple projects).

Requirements

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @slimio/utils
# or
$ yarn add @slimio/utils

Usage example

TBC

API

taggedString(chaines: string, ...keys: any[]): Clojure

This method is inspired from Tagged Literal (look at the MDN Documentation)

Useful to build string templates:

const { strictEqual } = require("assert");
const tpl = taggedString`hello ${0}`;

strictEqual(tpl("fraxken"), "hello fraxken");

Template properties can be either index or key:

const { strictEqual } = require("assert");
const tpl = taggedString`hello ${"name"}`;

strictEqual(tpl({ name: "fraxken" }), "hello fraxken");
createDirectory(path: string): void

Create a directory at the given path. This method trigger fs.mkdir but catch the ENOENT error if the directory exist.

assertEntity(entity: SlimIO.RawEntity): void

Assert an Entity Object.

assertEntity({
    name: "myEntity",
    description: "desc",
    parent: 10,
    descriptors: {}
});
assertMIC(mic: SlimIO.RawIdentityCard): void

Assert an MicIdentityCard Object.

assertMIC({
    name: "myMIC",
    entityId: 1,
    unit: "unit",
    interval: 10,
    max: 100,
    description: "desc"
});
assertAlarm(alarm: SlimIO.RawAlarm): void

Assert an Alarm Object.

assertAlarm({
    message: "message",
    severity: 1,
    entityId: 2,
    correlateKey: "test_corrKey"
});
assertCorrelateID(CID: SlimIO.CID): void

Assert a correlate id (Alarm correlate id). A CID is the addition of a Alarm ID and a Correlate key. The maximum length of the CID is 44.

assertCorrelateID("1#test_corrkey");
assertCK(correlateKey: string): void

Assert a correlate key (Alarm correlate key). The length of CK must be between 1 and 35.

assertCK("test_corrkey");
privateProperty(target: object, propertyKey: string|symbol|number, value?: any): void

Define a private (non-enumable, non-configurable) property on the target.

const assert = require("assert");

const obj = {};
privateProperty(obj, "foo", "bar");
assert.deepEqual(Object.keys(obj), []);

obj.foo = "world!";
assert.strictEqual(obj.foo, "world!");
assert.throws(() => {
    delete obj.foo;
}, { name: 'TypeError' });

Dependencies

Name Refactoring Security Risk Usage
@slimio/is Minor Low Type Checker

License

MIT