Skip to content

Commit fc2247d

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

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/utils/__tests__/scopes.spec.ts

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

src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55

66
export { default as max } from './max'
77
export { default as min } from './min'
8+
export { default as scopes } from './scopes'

src/utils/scopes.ts

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

0 commit comments

Comments
 (0)