Skip to content

Commit 5fad964

Browse files
committed
feat(utils): types
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent fc2247d commit 5fad964

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/utils/__tests__/types.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @file Unit Tests - types
3+
* @module commitlint-config/utils/tests/unit/types
4+
*/
5+
6+
import { Type } from '#src/enums'
7+
import testSubject from '../types'
8+
9+
describe('unit:utils/types', () => {
10+
it('should return array containing valid commit types', () => {
11+
// Arrange
12+
const extras: string[] = ['release', 'wip']
13+
14+
// Act + Expect
15+
expect(testSubject(extras)).to.include.members([
16+
...new Set<string>([...Object.values(Type), ...extras])
17+
])
18+
})
19+
})

src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
export { default as max } from './max'
77
export { default as min } from './min'
88
export { default as scopes } from './scopes'
9+
export { default as types } from './types'

src/utils/types.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @file Utilities - types
3+
* @module commitlint-config/utils/types
4+
*/
5+
6+
import { Type } from '#src/enums'
7+
import type { LiteralUnion } from '@flex-development/tutils'
8+
9+
/**
10+
* Returns an array of valid commit types.
11+
*
12+
* @param {(Set<string> | string[])?} [extras=[]] - Additional commit types
13+
* @return {LiteralUnion<Type, string>[]} Commit types array
14+
*/
15+
const types = (
16+
extras: Set<string> | string[] = []
17+
): LiteralUnion<Type, string>[] => {
18+
return [...new Set([...Object.values(Type), ...extras])].sort((t1, t2) => {
19+
return t1.localeCompare(t2)
20+
})
21+
}
22+
23+
export default types

0 commit comments

Comments
 (0)