-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
- Loading branch information
1 parent
b61f9ae
commit b3f2126
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @file Unit Tests - normalizeLib | ||
* @module tsconfig-utils/utils/tests/unit/normalizeLib | ||
*/ | ||
|
||
import LIB from '../lib' | ||
import testSubject from '../normalize-lib' | ||
|
||
describe('unit:utils/normalizeLib', () => { | ||
it('should return empty array if option cannot be normalized', () => { | ||
expect(testSubject(faker.string.sample())).to.be.empty | ||
}) | ||
|
||
it('should return normalized compiler option', () => { | ||
expect(testSubject([...LIB.keys()])).to.deep.equal([...LIB.values()]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @file Utilities - normalizeLib | ||
* @module tsconfig-utils/utils/normalizeLib | ||
*/ | ||
|
||
import type { Lib, LibFile } from '@flex-development/tsconfig-types' | ||
import { isString, isUndefined } from '@flex-development/tutils' | ||
import LIB from './lib' | ||
|
||
/** | ||
* Converts the given `option` to an array containing **programmatic** | ||
* [`lib`][1] options. | ||
* | ||
* TypeScript programs expect values defined in `compilerOptions.lib` to match | ||
* filenames in `node_modules/typescript/lib` exactly. | ||
* | ||
* [1]: https://www.typescriptlang.org/tsconfig#lib | ||
* | ||
* @param {unknown} option - Option to evaluate | ||
* @return {LibFile[]} Lib filename array | ||
*/ | ||
const normalizeLib = (option: unknown): LibFile[] => { | ||
return (Array.isArray(option) ? option : []) | ||
.filter(item => isString(item)) | ||
.map((name: string) => LIB.get(name as Lowercase<Lib>)) | ||
.filter(file => !isUndefined(file)) as LibFile[] | ||
} | ||
|
||
export default normalizeLib |