cullophid / date-fp

Functional programming date manipulation library
121 stars 17 forks source link

Add TypeScript typings #66

Closed EricCrosson closed 4 years ago

EricCrosson commented 4 years ago

Hello, great project! I have found it useful and wanted to contribute typescript typings. Here they are

declare module 'date-fp' {
    export function of(dateParts: number[]): Date;
    export function fromTime(time: number): Date;
    export function add(
        unit: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years',
        value: number,
        date: Date
    ): Date;
    export function clone(date: Date): Date;
    export function convertTo(
        unit: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days',
        date: Date
    ): number;
    export function diff(
        unit: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years',
        a: Date,
        b: Date
    ): number;
    export function equals(a: Date, b: Date): boolean;
    export function format(format: string, date: Date): string;
    export function get(
        property: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'date' | 'day' | 'week' | 'month' | 'year',
        date: Date
    ): number;
    export function isLeapYear(date: Date): boolean;
    export function isValid(date: Date): boolean;
    export function max(dates: Date[]): Date;
    export function min(dates: Date[]): Date;
    export function parse(format: string, date: string): Date;
    export function set(
        property: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'date' | 'week' | 'month' | 'year',
        value: number,
        date: Date
    ): Date;
    export function sub(
        unit: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years',
        value: number,
        date: Date
    ): Date;
    export function unixTime(date: Date): number;
}

For posterity.

While writing these out I noticed one function, get, is documented to return a Date but appears to return a number.

I will open a merge request to integrate these changes, but I'm having trouble building the project on my machine -- after npm install and npm run build, I see

λ npm run build    

> date-fp@5.0.3 build /Users/eric/workspace/github/date-fp
> npm run webpack && npm run uglify && npm run build:modules

npm WARN invalid config loglevel="notice"

> date-fp@5.0.3 webpack /Users/eric/workspace/github/date-fp
> webpack src/index.js build/date-fp.js --config webpack.config.js

Hash: d245f5e1c8539b1771c6
Version: webpack 1.15.0
Time: 624ms
     Asset     Size  Chunks             Chunk Names
date-fp.js  64.3 kB       0  [emitted]  main
    + 20 hidden modules
npm WARN invalid config loglevel="notice"

> date-fp@5.0.3 uglify /Users/eric/workspace/github/date-fp
> uglifyjs build/date-fp.js -o build/date-fp.min.js --source-map build/date-fp.min.map -p relative

Supported options:
  content         null
  filename        null
  includeSources  false
  root            null
  url             null
ERROR: `build/date-fp.min.map` is not a supported option
    at DefaultsError.get (eval at <anonymous> (/Users/eric/workspace/github/date-fp/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:71:23)
    at fatal (/Users/eric/workspace/github/date-fp/node_modules/uglify-js/bin/uglifyjs:298:27)
    at run (/Users/eric/workspace/github/date-fp/node_modules/uglify-js/bin/uglifyjs:241:9)
    at Object.<anonymous> (/Users/eric/workspace/github/date-fp/node_modules/uglify-js/bin/uglifyjs:167:5)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
    at internal/main/run_main_module.js:17:11

npm ERR! Darwin 18.7.0
npm ERR! argv "/usr/local/Cellar/node/12.12.0/bin/node" "/Users/eric/workspace/github/date-fp/node_modules/.bin/npm" "run" "uglify"
npm ERR! node v12.12.0
npm ERR! npm  v2.14.8
npm ERR! code ELIFECYCLE
npm ERR! date-fp@5.0.3 uglify: `uglifyjs build/date-fp.js -o build/date-fp.min.js --source-map build/date-fp.min.map -p relative`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the date-fp@5.0.3 uglify script 'uglifyjs build/date-fp.js -o build/date-fp.min.js --source-map build/date-fp.min.map -p relative'.
npm ERR! This is most likely a problem with the date-fp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     uglifyjs build/date-fp.js -o build/date-fp.min.js --source-map build/date-fp.min.map -p relative
npm ERR! You can get their info via:
npm ERR!     npm owner ls date-fp
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/eric/workspace/github/date-fp/npm-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! date-fp@5.0.3 build: `npm run webpack && npm run uglify && npm run build:modules`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the date-fp@5.0.3 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/eric/.npm/_logs/2019-11-11T15_12_29_178Z-debug.log

Have I gone about building the project the right way?

I am not very familiar with any parts of this build system so it may take a prohibitive amount of time to resuscitate. I notice it has been a few years since deps were updated so things may have gotten a bit wonky. Any guidance would be appreciated

Thanks again for date-fp!

EricCrosson commented 4 years ago

I was able to add the types through DefinitelyTyped, calling this closed! Cheers

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/40307#event-2789306937