lukeed / klona

A tiny (240B to 501B) and fast utility to "deep clone" Objects, Arrays, Dates, RegExps, and more!
MIT License
1.62k stars 43 forks source link

JSDoc + named export #10

Closed loucyx closed 4 years ago

loucyx commented 4 years ago

Love the simplicity of the code @lukeed! This ticket is just 2 suggestions, not issues at all:

  1. It would be great to have a named export besides the default, meaning:
    export const klona = target => { // ...
    export default klona

    So the devs can do both of these:

    import klona from "klona";
    import { klona } from "klona";
  2. If you add JSDocs to Klona and remove the d.ts file, you can use typescriptas a devDependency to generate the d.ts automatically from the docs. So if you do something like this:
    /**
    * Tiny & fast deep-clone.
    *
    * @template TargetType
    * @param {TargetType} target Target to be cloned.
    * @returns {TargetType}
    */
    const klona = target => { // ...

    And then you run tsc (having a tsconfig.json which has allowJs set to true, and declaration set to true), you'll get a d.ts file like this:

    export function klona<TargetType>(target: TargetType): TargetType;
    export default klona;

    So if you add tsc to your build as a last step, you can work in the JS only and forget about the d.ts.

If you want me to lend you a hand with any of this suggestions, I can create an PR for it 😄

lukeed commented 4 years ago

Hey thank you for the suggestions, but no thanks.

I have my patterns and tooling in place as the result of publishing many modules. Plus that's a lot of extra tooling for a single line d.ts file 😜

It's also a default export because there's only one function to this module & that's very likely to never change.

Thanks!