Skip to content

Commit

Permalink
feat: isShellSupported
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Feb 1, 2024
1 parent 3dc02a3 commit f016d8b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ const { tabtabDebug, systemShell } = require('./utils');
// TABTAB_DEBUG file provided.
const debug = tabtabDebug('tabtab');

/**
* Check if a shell is supported.
* @param {String} shell - Shell to check.
* @returns {shell is SupportedShell}
*/
const isShellSupported = shell => (/** @type {ReadonlyArray.<String>} */ (SUPPORTED_SHELLS)).includes(shell);

/**
* Construct a completion script.
* @param {Object} options - Options object.
Expand Down Expand Up @@ -247,6 +254,7 @@ const logFiles = () => {
module.exports = {
SUPPORTED_SHELLS,
shell: systemShell,
isShellSupported,
getCompletionScript,
install,
uninstall,
Expand Down
15 changes: 15 additions & 0 deletions test/isShellSupported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const assert = require('assert');
const { isShellSupported, SUPPORTED_SHELLS } = require('..');

describe('isShellSupported', () => {
it('returns true for supported shells', () => {
assert.deepStrictEqual(
SUPPORTED_SHELLS.filter(shell => isShellSupported(shell)),
SUPPORTED_SHELLS,
);
})

it('returns false for unsupported shells', () => {
assert.strictEqual(isShellSupported('unknown'), false);
})
})

0 comments on commit f016d8b

Please sign in to comment.