felixge / node-dateformat

A node.js package for Steven Levithan's excellent dateFormat() function.
MIT License
1.3k stars 156 forks source link

Will there be a typings file? #48

Open Cyber1000 opened 8 years ago

Cyber1000 commented 8 years ago

I'm using your component, but I would like to use it a little bit more typesave. I'm using typescript: Is there some typedefintion out there for dateformat (official/inofficial) or are you planning to provide one .d.ts-File?

Thanks!

anandsainath commented 8 years ago

Looks like someone else has created a typings for this. Isn't very hard as you can see - https://github.com/nozzlegear/dateformat.d.ts

lucastheisen commented 7 years ago

It is simple enough to declare your own, but much more convenient if this is included in the lib. This is what I am using:

declare module 'dateformat' {
  interface _dateformat {
    /**
     * Returns a string representing date using format mask.
     * 
     * @param {Date} date The date
     * @param {string} mask The format mask
     */
    (date: Date, mask: string): string
    /**
     * Returns a string representing date using the default
     * format mask.
     * 
     * @param {Date} date The date
     */
    (date: Date): string
    /**
     * Returns a string representing the current date (now) 
     * using format mask.
     * 
     * @param {string} mask The format mask
     */
    (mask: string): string

    readonly masks: {
      default: string,
      shortDate: string,
      mediumDate: string,
      longDate: string,
      fullDate: string,
      shortTime: string,
      mediumTime: string,
      longTime: string,
      isoDate: string,
      isoTime: string,
      isoDateTime: string,
      isoUtcDateTime: string,
      expiresHeaderFormat: string
    }

    i18n: {
      dateNames: string[],
      monthNames: string[]
    }
  }
  let dateformat: _dateformat
  export default dateformat;
}

It could probably use a little more jsdoc describing the masks, and how to override i18n, but it works for me. I could create a pull request if you want...

mjwloch commented 6 years ago

There is a separate npm package with typings: @types/dateformat that you can install.