This file contains hidden or 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
/** | |
* An efficient TypeScript utility type to transform a union of objects into the intersection of such objects. | |
* | |
* - TypeScript 5.8.2 | |
* - Benchmarked against the similar type declared at [utility-types](https://github.com/piotrwitek/utility-types): | |
* - `utility-types`: ~250ms | |
* - `this`: ~30ms | |
* | |
* - This haven't been deeply tested for correctness yet. | |
*/ |
This file contains hidden or 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
type DeepKeys<M> = { | |
[J in keyof M as `${J & string}${ | |
M[J] extends Record<string, any> ? | |
M[J] extends {constructor: M[J]} ? '' : | |
M[J] extends Array<any> ? '' : | |
`.${keyof DeepKeys<M[J]> & string}` : '' | |
}`]: | |
M[J] extends Record<string, any> ? M : M[J] | |
} |
This file contains hidden or 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
import os | |
def dirtree(path): | |
steps = list(os.walk(path)) | |
def _tree(): | |
_, child_dirs, files = steps.pop(0) | |
obj = { child: _tree() for child in child_dirs } | |
obj['__files__'] = files | |
return obj | |
return _tree() |