Skip to content

Commit

Permalink
Allow any length for pattern pieces (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
C-D-Lewis authored Sep 18, 2019
1 parent 0fc6803 commit eeea4a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/modules/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,17 @@ const showSyntax = (command) => {
throw new Error(`Available operations for '${firstArg}':\n${specs.join('\n')}`);
};

/**
* Take an arg and pattern spec piece and validate they match.
*
* @param {string} arg - The argument value, such as 'Ur2Ta6GEFfVAfbCdFd7KnpTd'
* @param {string} spec - The pattern spec piece, such as '$id'
* @returns {boolean} true if the arg should validate.
*/
const matchArg = (arg = '', spec) => {
const map = {
// Value must be an EVRYTHNG ID
$id: val => val.length === 24,
// Value can be an EVRYTHNG ID, an identifier string, or some customer ID format
$id: val => val.length > 0,
// Value must be JSON
$payload: (val) => {
// Some switches work instead of a payload
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('commands', () => {
it('should throw to identify a partial match', () => {
const args = ['thngs'];
const match = () => commands.identify(args);

expect(match).to.throw();
});

Expand Down

0 comments on commit eeea4a6

Please sign in to comment.