Skip to content

Commit 39bfe07

Browse files
committed
feat(utils): max
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 8e699cf commit 39bfe07

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
export * from './enums'
77
export * from './interfaces'
88
export * from './types'
9+
export * from './utils'

src/utils/__tests__/max.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @file Unit Tests - max
3+
* @module commitlint-config/utils/tests/unit/max
4+
*/
5+
6+
import { Scope } from '#src/enums'
7+
import testSubject from '../max'
8+
9+
describe('unit:utils/max', () => {
10+
it('should return length of longest string in given array', () => {
11+
// Arrange
12+
const array: Scope[] = [Scope.BUILD, Scope.COMPONENTS, Scope.YARN]
13+
14+
// Act + Expect
15+
expect(testSubject(array)).to.equal(Scope.COMPONENTS.length)
16+
})
17+
})

src/utils/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @file Entry Point - Utilities
3+
* @module commitlint-config/utils
4+
*/
5+
6+
export { default as max } from './max'

src/utils/max.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @file Utilities - max
3+
* @module commitlint-config/utils/max
4+
*/
5+
6+
/**
7+
* Returns the length of the longest string in the given `array`.
8+
*
9+
* @param {string[]} array - Array to evaluate
10+
* @return {number} Length of longest string in `array`
11+
*/
12+
const max = (array: string[]): number => {
13+
return array.reduce((max: number, str: string): number => {
14+
return str.length > max ? str.length : max
15+
}, 0)
16+
}
17+
18+
export default max

0 commit comments

Comments
 (0)