RuleSet(title)

A collection of one or more modification rules.

Constructor

new RuleSet(title)

Parameters:
Name Type Description
title string

Title of this ruleset

Source:
RuleSet.js, line 12
Example
let rules = new RuleSet('My Rules');
Create a new RuleSet

Classes

RuleSet

Members

io IO

IO object for reading/writing this ruleset from/to a file.

Source:
RuleSet.js, line 49

rules Rule[]

Added rules.

Source:
RuleSet.js, line 44

title string

Title of this RuleSet, which is recognized by Karabiner.

Source:
RuleSet.js, line 39

Methods

add(rule)Rule

Adds an rule to this ruleset.
If the provided argument is a string, a new instance of Rule will be created with the string as its description.
If the provided argument is an instance of Rule, simply adds it to the collection.

Parameters:
Name Type Description
rule

rule description or an instance of Rule

Source:
RuleSet.js, line 95
Returns:

added rule

Type:
Rule
Examples
let rule = rules.add('My 1st rule');
Adding a new rule with description
let rule = rules.add(new Rule('My 1st rule'));
Adding a rule instance

load()RuleSet

Loads data from the ruleset file.

Source:
RuleSet.js, line 117
Returns:

Itself

Type:
RuleSet

loadJSON(data)RuleSet

Loads JSON data.

Parameters:
Name Type Description
data
  • string
  • object

JSON string or object

Source:
RuleSet.js, line 105
Returns:

Itself

Type:
RuleSet

out()

Outputs JSON representation of this ruleset to STDOUT.

Source:
RuleSet.js, line 70

save()RuleSet

Saves this ruleset to the given file in JSON format.

Source:
RuleSet.js, line 126
Returns:

Itself

Type:
RuleSet

setIO(file, optsopt)RuleSet

Setup IO object for reading/writing this ruleset from/to a file.
Ruleset files are normally located at ~/.config/karabiner/complex_modifications/*.json.

Parameters:
Name Type Description
file string

Ruleset file path

optsopt object

IO options

Source:
RuleSet.js, line 80
Returns:

Itself

Type:
RuleSet

toJSON(stringifyopt)objectstring

Returns a JSON representation of this ruleset.

Parameters:
Name Type Default Description
stringifyopt boolean false

If true, returns a stringified result

Source:
RuleSet.js, line 60
Returns:

An object like: { title: ... , rules: ... }

Type:
  • object
  • string
Example
let rules = new RuleSet('My Rules');
let obj = rules.toJSON();
console.log( obj.title ); // 'My Rules'

staticfromFile(file, optsopt)RuleSet

Instantiates RuleSet from a JSON file.
Ruleset files are normally located at ~/.config/karabiner/complex_modifications/*.json.

Parameters:
Name Type Description
file string

JSON file path

optsopt object

IO options

Source:
RuleSet.js, line 28
Returns:

New instance

Type:
RuleSet

staticfromJSON(data)RuleSet

Instantiates RuleSet from a JSON string or object.

Parameters:
Name Type Description
data
  • string
  • object

JSON string or object

Source:
RuleSet.js, line 18
Returns:

New instance

Type:
RuleSet