Nationwide Polamorous Matrimony


    1.5.0 • Public • Published




    Global functions


    timeInMillisecondsToLocalTimeString (timestamp)

    Converts a timestamp to a string with the local time of day in brackets

    timeInMillisecondsToLocalTimeString Parameters

    Name Type Description
    timestamp number timestamp in milliseconds

    Class ProcessRule

    new ProcessRule(variables, date, longitude, latitude)

    Processes rules based on a set of variables

    ProcessRule Parameters

    Name Type Attribute Default Description
    variables Object optional { } key/value map where key is the variable name ( usually a topic string )
    date Date optional now current date
    longitude number optional 51 . 476852 geographical longitued poistion of the automation target in degrees
    latitude number optional -0 . 000500 geographical latitued poistion of the automation target in degrees

    ProcessRule Members

    Name Type description
    date @type Gets the current date/time
    date @type Sets the current date/time
    variables @type Sets all variables

    ProcessRule Methods


    check (rule, motionEvents, nonMotionEvents) => {Object.<messages:Message[], usedVariables>}

    Processes a rule and if the rule demands , create a message

    check Parameters
    Name Type Attribute Description
    rule Object rule to check
    motionEvents Object optional map { topic : timestamp } list of events classified as motions
    nonMotionEvents Object optional { topic : true } list of events not classified as motions
    check throws
    Type Description
    Error on error in the decision rule
    check returns
    Type Description
    Object.<messages:Message[], usedVariables> Array of messages and object of variables used .


    determineNeededVariables (rule) => {Object}

    Gets a list of needed variables for the rule

    determineNeededVariables Parameters
    Name Type Description
    rule Object rule to check
    determineNeededVariables returns
    Type Description
    Object { name : value } list of needed variables including current value


    setVariable (name, value)

    Sets a single variable

    setVariable Parameters
    Name Type Description
    name string name of the variable to set
    value \* value of the variable to set

    Class Rules

    new Rules(rulesTree, check)

    Creates an object holding automation rules


    const rulesTree =
          location1: {
              rules: {
                  rule1: {
                      title: 'hello'
                  rule2: {
                      title: 'world'
          location2: {
              rule1: {
                  error: 'faulty rule'
    const checkRule = new CheckInput({ type: 'object', properties: { title: { type: string } }, required: ['title'] })
    const rules = new Rules(rulesTree, checkRules)
    console.log(rules.rules.length) // prints 1, we have one correct rule
    console.log(rules.invalidRules[0].messages) // prints the error messages for rule 'location2'

    Rules Parameters

    Name Type Description
    rulesTree Object rules tree
    check CheckInput definition to check the validity of a rule

    Rules Members

    Name Type description
    invalidRules @type Get the invalid rules list
    rules @type Get the valid rules list

    Rules Methods


    invalidateRule (name, messages)

    Invalidates a rule , because it generates an error

    invalidateRule Parameters
    Name Type Attribute Description
    name string name of the rule to invalidate
    messages Array.<string> optional error messages


    npm i @mangar2/rules

    DownloadsWeekly Downloads






    Unpacked Size

    1.14 MB

    Total Files


    Last publish


    • mangar2