forked from jakesgordon/javascript-state-machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
41 lines (41 loc) · 1.05 KB
/
util.js
File metadata and controls
41 lines (41 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export class Exception {
constructor (message, transition, from, to, current) {
this.message = message;
this.transition = transition;
this.from = from;
this.to = to;
this.current = current;
}
}
export function camelize(label) {
if (label.length === 0) {
return label;
}
let words = label.split(/[_-]/);
// single word with first character already lowercase, return untouched
if ((words.length === 1) && (words[0][0].toLowerCase() === words[0][0])) {
return label;
}
let result = words[0].toLowerCase();
for (let word of words.slice(1)) {
result += word.charAt(0).toUpperCase() + word.substring(1).toLowerCase();
}
return result;
}
export function prepend(prepend, label) {
label = camelize(label);
return prepend + label[0].toUpperCase() + label.substring(1);
}
export function hook(fsm, name, additional) {
let plugins = fsm.config.plugins;
let args = [fsm.context];
if (additional) {
args = args.concat(additional);
}
for (let plugin of plugins) {
let method = plugin[name];
if (method) {
method.apply(plugin, args);
}
}
}