Skip to content

Commit

Permalink
feat(action-code): concat ActionCodes together
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed Sep 12, 2018
1 parent 867a83c commit 5b0b4a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions action-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class ActionCode {
}

static concat(prefix, action) {
if (prefix instanceof ActionCode) {
prefix = prefix.code
}
if (action instanceof ActionCode) {
action = action.code
}
if (prefix instanceof RegExp) {
throw new TypeError('concat to an RegExp is currently not supported. Open an Issue for it.')
}
Expand Down
5 changes: 5 additions & 0 deletions action-code.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ test('static concat', t => {
t.is(ActionCode.concat('a:b', 'c:d').get(), 'a:b:c:d')
})

test('concat an ActionCode', t => {
t.is(ActionCode.concat('main', new ActionCode('a')).get(), 'a')
t.deepEqual(ActionCode.concat('b', new ActionCode(/(.+)/i)).get(), /^b:(.+)$/i)
})

test('regex', t => {
t.deepEqual(new ActionCode(/(.+)/).get(), /^(.+)$/)
t.deepEqual(new ActionCode(/(.+)/i).get(), /^(.+)$/i)
Expand Down

0 comments on commit 5b0b4a7

Please sign in to comment.