-
-
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 <[email protected]>
- Loading branch information
1 parent
d2c2018
commit efd4d09
Showing
13 changed files
with
398 additions
and
13 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ iife | |
infile | ||
jsonifiable | ||
keyid | ||
ksort | ||
larsgw | ||
lcov | ||
lintstagedrc | ||
|
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
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,44 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`unit:utils/ksort > arrays > deep > should return obj with item keys sorted deeply 1`] = ` | ||
[ | ||
{ | ||
"make": "lexus", | ||
"model": "lc", | ||
"vin": "0WBW1G4D29TC62167", | ||
"year": 2023, | ||
}, | ||
[Circular], | ||
] | ||
`; | ||
|
||
exports[`unit:utils/ksort > plain objects > deep > should return obj with nested and top-level keys sorted 1`] = ` | ||
{ | ||
"circular": [Circular], | ||
"driver": { | ||
"first_name": "tres", | ||
"last_name": "koelpin", | ||
"nanoid": "mhR2OWSEhQFXkwU1NJY23", | ||
}, | ||
"make": "lexus", | ||
"model": "lc", | ||
"riders": [ | ||
{ | ||
"first_name": "adrian", | ||
"last_name": "rodriguez", | ||
"uuid": "19fd6413-7fc9-4e7f-a5b5-9a3689d25134", | ||
}, | ||
], | ||
"vin": "0WBW1G4D29TC62167", | ||
"year": 2023, | ||
} | ||
`; | ||
|
||
exports[`unit:utils/ksort > plain objects > should return obj with top-level keys sorted 1`] = ` | ||
{ | ||
"make": "lexus", | ||
"model": "lc", | ||
"vin": "0WBW1G4D29TC62167", | ||
"year": 2023, | ||
} | ||
`; |
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,20 @@ | ||
/** | ||
* @file Type Tests - KsortOptions | ||
* @module tutils/utils/tests/unit-d/KsortOptions | ||
*/ | ||
|
||
import type { Nilable } from '#src/types' | ||
import type AlphabetizeOptions from '../alphabetize.options' | ||
import type TestSubject from '../ksort.options' | ||
|
||
describe('unit-d:utils/KsortOptions', () => { | ||
it('should extend AlphabetizeOptions', () => { | ||
expectTypeOf<TestSubject>().toMatchTypeOf<AlphabetizeOptions>() | ||
}) | ||
|
||
it('should match [deep?: Nilable<boolean>]', () => { | ||
expectTypeOf<TestSubject>() | ||
.toHaveProperty('deep') | ||
.toEqualTypeOf<Nilable<boolean>>() | ||
}) | ||
}) |
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 Type Tests - ksort | ||
* @module tutils/utils/tests/unit-d/ksort | ||
*/ | ||
|
||
import type Vehicle from '#fixtures/types/vehicle' | ||
import type testSubject from '../ksort' | ||
|
||
describe('unit-d:utils/ksort', () => { | ||
it('should return T', () => { | ||
// Arrange | ||
type T = Vehicle | ||
|
||
// Expect | ||
expectTypeOf<typeof testSubject<T>>().returns.toEqualTypeOf<T>() | ||
}) | ||
}) |
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,109 @@ | ||
/** | ||
* @file Unit Tests - ksort | ||
* @module tutils/utils/tests/unit/ksort | ||
*/ | ||
|
||
import type Vehicle from '#fixtures/types/vehicle' | ||
import VEHICLE, { VEHICLE_TAG } from '#fixtures/vehicle' | ||
import type { Opaque } from '#src/types' | ||
import cast from '../cast' | ||
import define from '../define' | ||
import testSubject from '../ksort' | ||
|
||
describe('unit:utils/ksort', () => { | ||
let vehicle: Opaque<Vehicle, 'vehicle'> | ||
|
||
beforeAll(() => { | ||
vehicle = cast({ year: 2023, vin: VEHICLE.vin, model: 'lc', make: 'lexus' }) | ||
|
||
define(vehicle, VEHICLE_TAG, { | ||
configurable: false, | ||
enumerable: false, | ||
value: 'vehicle', | ||
writable: false | ||
}) | ||
}) | ||
|
||
it('should return obj if obj is not an array or plain object', () => { | ||
// Arrange | ||
const obj: Set<Vehicle> = new Set([vehicle]) | ||
|
||
// Act + Expect | ||
expect(testSubject(obj)).to.equal(obj) | ||
}) | ||
|
||
describe('arrays', () => { | ||
it('should return obj if item keys should not be sorted', () => { | ||
// Arrange | ||
const obj: [Vehicle] = [vehicle] | ||
|
||
// Act + Expect | ||
expect(testSubject(obj)).to.equal(obj) | ||
}) | ||
|
||
describe('deep', () => { | ||
let obj: (Vehicle | Vehicle[])[] | ||
|
||
beforeAll(() => { | ||
obj = [vehicle] | ||
obj.push(cast(obj)) | ||
}) | ||
|
||
it('should return obj with item keys sorted deeply', () => { | ||
// Act | ||
const result = testSubject(obj, { deep: true }) | ||
|
||
// Expect | ||
expect(result).to.eql(obj).and.equal(obj) | ||
expect(result).toMatchSnapshot() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('plain objects', () => { | ||
it('should return obj with top-level keys sorted', () => { | ||
// Act | ||
const result = testSubject(vehicle) | ||
|
||
// Expect | ||
expect(result).to.eql(vehicle).and.equal(vehicle) | ||
expect(result).toMatchSnapshot() | ||
}) | ||
|
||
describe('deep', () => { | ||
let obj: Vehicle & { | ||
driver: { first_name: string; last_name: string; nanoid: string } | ||
riders: { first_name: string; last_name: string; uuid: string }[] | ||
} | ||
|
||
beforeAll(() => { | ||
obj = { | ||
...vehicle, | ||
driver: { | ||
nanoid: 'mhR2OWSEhQFXkwU1NJY23', | ||
last_name: 'koelpin', | ||
first_name: 'tres' | ||
}, | ||
riders: [ | ||
{ | ||
uuid: '19fd6413-7fc9-4e7f-a5b5-9a3689d25134', | ||
last_name: 'rodriguez', | ||
first_name: 'adrian' | ||
} | ||
] | ||
} | ||
|
||
define(obj, 'circular', { value: obj }) | ||
}) | ||
|
||
it('should return obj with nested and top-level keys sorted', () => { | ||
// Act | ||
const result = testSubject(obj, { deep: true }) | ||
|
||
// Expect | ||
expect(result).to.eql(obj).and.equal(obj) | ||
expect(result).toMatchSnapshot() | ||
}) | ||
}) | ||
}) | ||
}) |
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
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,25 @@ | ||
/** | ||
* @file Utilities - KsortOptions | ||
* @module tutils/utils/ksort/options | ||
*/ | ||
|
||
import type { Nilable } from '#src/types' | ||
import type AlphabetizeOptions from './alphabetize.options' | ||
|
||
/** | ||
* Property key sorting options. | ||
* | ||
* @see {@linkcode AlphabetizeOptions} | ||
* | ||
* @extends {AlphabetizeOptions} | ||
*/ | ||
interface KsortOptions extends AlphabetizeOptions { | ||
/** | ||
* Recursively sort keys, including keys of plain objects within arrays. | ||
* | ||
* @default false | ||
*/ | ||
deep?: Nilable<boolean> | ||
} | ||
|
||
export type { KsortOptions as default } |
Oops, something went wrong.