From 5b0b4a7cf8a5fd10be4d48fdccb0a248bf1cea1f Mon Sep 17 00:00:00 2001 From: Edgar To Date: Thu, 13 Sep 2018 01:33:22 +0200 Subject: [PATCH] feat(action-code): concat ActionCodes together --- action-code.js | 6 ++++++ action-code.test.js | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/action-code.js b/action-code.js index cd5b5a0..18eb432 100644 --- a/action-code.js +++ b/action-code.js @@ -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.') } diff --git a/action-code.test.js b/action-code.test.js index 8ecce64..9195f78 100644 --- a/action-code.test.js +++ b/action-code.test.js @@ -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)