Skip to content

Commit 35f806c

Browse files
committed
chore: Refactoring
1 parent df84f19 commit 35f806c

10 files changed

+17
-5
lines changed

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: [Akurganow]
4+
patreon: akurganow
5+
# pen_collective: # Replace with a single Open Collective username
6+
# ko_fi: # Replace with a single Ko-fi username
7+
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
# liberapay: # Replace with a single Liberapay username
10+
# issuehunt: # Replace with a single IssueHunt username
11+
# otechie: # Replace with a single Otechie username
12+
# custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

__tests__/filter-by-same-key-value.test.ts renamed to __tests__/filterBySameKeyValue.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import filterBySameKeyValue from '../src/filterBySameKeyValue'
22

3-
describe('filterBySameValue', () => {
3+
describe('filterBySameKeyValue', () => {
44
test('should filter by same value', () => {
55
function filterBySameId<T extends { id: string }>(item: T, index: number, array: T[]) {
66
return filterBySameKeyValue<T>(item, index, array, 'id')
File renamed without changes.

__tests__/is-sorted-by.test.ts renamed to __tests__/isSortedBy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('isSortedBy', () => {
2424
test('not an array of objects', () => {
2525
const items = ['a', 'b', 'c'] as unknown as Array<{ id: string }>
2626

27-
expect(() => isSortedBy(items, 'id')).toThrowErrorMatchingInlineSnapshot('"Array is not an array of objects. (string)"')
27+
expect(() => isSortedBy(items, 'id')).toThrowErrorMatchingInlineSnapshot('"Array is not an array of objects."')
2828
})
2929
test('string', () => {
3030
const itemsAsc = [{ id: 'a' }, { id: 'b' }, { id: 'c' }]
File renamed without changes.
File renamed without changes.

src/isSortedBy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Sortable, SortableKey, SortableOrder } from './types'
22
import { DEFAULT_ORDER } from './constants'
3-
import { isObject } from '@plq/is'
3+
import { isFunction, isObject } from '@plq/is'
44

55
import isSortedValues from './isSortedValues'
66

@@ -18,11 +18,11 @@ import isSortedValues from './isSortedValues'
1818
export default function isSortedBy<T extends Sortable<T>>(array: T[], key: SortableKey<T>, order: SortableOrder = DEFAULT_ORDER): boolean {
1919
if (array.length <= 1) return true
2020

21-
if (!isObject(array[0])) throw new Error(`Array is not an array of objects. (${typeof array[0]})`)
21+
if (array.some(item => !isObject(item))) throw new Error('Array is not an array of objects.')
2222

2323
const mapped = (array as Sortable<T>[])
2424
.map(item => {
25-
if (typeof item[key] === 'function') {
25+
if (isFunction(item[key])) {
2626
return (item[key] as (() => string | number))() as string | number
2727
} else {
2828
return item[key] as unknown as string | number

0 commit comments

Comments
 (0)