File tree Expand file tree Collapse file tree 5 files changed +113
-0
lines changed
Expand file tree Collapse file tree 5 files changed +113
-0
lines changed Original file line number Diff line number Diff line change 1+ *
2+ ! ** /* .d.ts
3+ ! ** /* .d.cts
4+ ! ** /* .d.mts
5+ ! ** /* .d. * .ts
Original file line number Diff line number Diff line change 1+ /**
2+ * Options for sorting object keys by length.
3+ */
4+ interface SortKeysLengthOptions {
5+ /**
6+ * Recursively sort keys.
7+ * @default false
8+ */
9+ deep ?: boolean ;
10+ }
11+
12+ /**
13+ * Sort object keys by length in ascending order (shortest first).
14+ *
15+ * @param object - Object to sort
16+ * @param options - Sort options
17+ * @returns A new object with keys sorted by length in ascending order
18+ *
19+ * @example
20+ * ```javascript
21+ * sortKeysLength.asc({ab: 'x', a: 'y', abc: 'z'});
22+ * //=> {a: 'y', ab: 'x', abc: 'z'}
23+ * ```
24+ */
25+ declare function asc < T extends object > ( object : T , options ?: SortKeysLengthOptions ) : T ;
26+
27+ /**
28+ * Sort object keys by length in descending order (longest first).
29+ *
30+ * @param object - Object to sort
31+ * @param options - Sort options
32+ * @returns A new object with keys sorted by length in descending order
33+ *
34+ * @example
35+ * ```javascript
36+ * sortKeysLength.desc({ab: 'x', a: 'y', abc: 'z'});
37+ * //=> {abc: 'z', ab: 'x', a: 'y'}
38+ * ```
39+ */
40+ declare function desc < T extends object > ( object : T , options ?: SortKeysLengthOptions ) : T ;
41+
42+ export { asc , desc , SortKeysLengthOptions } ;
Original file line number Diff line number Diff line change 1+ {
2+ "private" : true ,
3+ "name" : " @types/sort-keys-length" ,
4+ "version" : " 2.0.9999" ,
5+ "projects" : [
6+ " https://github.com/kevva/sort-keys-length"
7+ ],
8+ "devDependencies" : {
9+ "@types/sort-keys-length" : " workspace:."
10+ },
11+ "owners" : [
12+ {
13+ "name" : " gaspard" ,
14+ "githubUsername" : " gasp"
15+ }
16+ ]
17+ }
Original file line number Diff line number Diff line change 1+ import { asc , desc } from "sort-keys-length" ;
2+
3+ // Test ascending sort
4+ const ascResult = asc ( { ab : "x" , a : "y" , abc : "z" } ) ;
5+
6+ // Test descending sort
7+ const descResult = desc ( { ab : "x" , a : "y" , abc : "z" } ) ;
8+
9+ // Test with deep option
10+ const deepAsc = asc ( { ab : "x" , a : "y" } , { deep : true } ) ;
11+ const deepDesc = desc ( { ab : "x" , a : "y" } , { deep : false } ) ;
12+
13+ // Test with nested objects
14+ const nested = asc ( {
15+ longKey : {
16+ short : 1 ,
17+ longerKey : 2 ,
18+ } ,
19+ a : "value" ,
20+ } , { deep : true } ) ;
21+
22+ // Type preservation
23+ interface MyObject {
24+ foo : string ;
25+ barbaz : number ;
26+ }
27+
28+ const typed : MyObject = { foo : "hello" , barbaz : 42 } ;
29+ const sortedTyped : MyObject = asc ( typed ) ;
30+ const sortedTypedDesc : MyObject = desc ( typed ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "module" : " node16" ,
4+ "lib" : [
5+ " es6"
6+ ],
7+ "noImplicitAny" : true ,
8+ "noImplicitThis" : true ,
9+ "strictNullChecks" : true ,
10+ "strictFunctionTypes" : true ,
11+ "types" : [],
12+ "noEmit" : true ,
13+ "forceConsistentCasingInFileNames" : true
14+ },
15+ "files" : [
16+ " index.d.ts" ,
17+ " sort-keys-length-tests.ts"
18+ ]
19+ }
You can’t perform that action at this time.
0 commit comments