New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FP function generation (closes #253) #393
Conversation
scripts/build_fp.js
Outdated
.concat('') | ||
.join('\n') | ||
|
||
const fpFnWithOptionsLines = ['// This file is generated automatically. Please don\'t change it.'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please point to this script in the comment (here and everywhere in such comments). Also Please,
docs/Options.js
Outdated
* Specifies, which way to round partial units. Options: 'floor', 'ceil', 'round' | ||
* @property {'s'|'m'|'h'|'d'|'M'|'Y'} [unit] - used by `distanceInWordsStrict`. | ||
* If specified, will force a unit | ||
* @property {'floor'|'ceil'|'round'} [partialMethod='floor'] - used by `distanceInWordsStrict`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 {0 | 1 | 2}
has inner spacing, while {'floor'|'ceil'|'round'}
doesn't. Let's make it consistent.
scripts/build_fp.js
Outdated
.concat('') | ||
.concat(`var ${name}WithOptions = convertToFpWithOptions(fn, ${arity})`) | ||
.concat('') | ||
.concat(`module.exports = ${name}WithOptions`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's generate ES6 versions here, ES5 versions will be compiled by Babel.
@mattlewis92 hello, could you please give me a hand here? I tried to make TypeScript typings for FP functions #253 but I don't know how to do it correctly |
Happy to help 😄 I can't see from the diff what issues you're facing, can you give me a specific example of where you're running into trouble? |
@mattlewis92 I generated a bunch of FP functions like these: 39af0f2#diff-0777f5ac1c488eba0e7fe9c0d2629658R1 They come in two variations, with options and without them: // regular function, from ./src/add_days
addDays(date, amount, options)
// FP function, from ./src/fp/addDays:
addDays(amount)(date)
// FP function with options, from ./src/fp/addDaysWithOptions
addDaysWithOptions(options)(amount)(date) Basically, they are the same as regular functions but the order of arguments is reversed and arguments are curried: import _addDays from 'date-fns/add_days'
const addDays = (b) => (a) => _addDays(a, b)
const addDaysWithOptions = (options) => (b) => (a) => _addDays(a, b, options) I wanted to generate TypeScript typings for them: |
Ah ok, maybe adding an e2e typescript test would be a good idea, similar to how definitely typed works? |
Could you please elaborate what do you mean or give an example?
… On 18 Jan 2017, at 18:53, Matt Lewis ***@***.***> wrote:
Ah ok, maybe adding an e2e typescript test would be a good idea, similar to how definitely typed works?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#393 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAikL7AzSKNwa5YlR0XECplQ-VNcJgYTks5rTl-vgaJpZM4Li4Vw>.
|
So every lib on definitely typed has the typings and then a test file that uses the typings in some example usage. The idea is that if tsc can compile them then the typings are valid. For example: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/webpack |
@mattlewis92 Oh, gotcha. I'll think about it. Well, for now, is declare module 'date-fns/fp' {
let addDays: (number) => (Date | string | number) => (Date)
namespace addDays {}
}
declare module 'date-fns/fp/addDays' {
import {addDays} from 'date-fns/fp'
export = addDays
}
declare module 'date-fns/fp/addDays/index' {
import {addDays} from 'date-fns/fp'
export = addDays
} is the correct TypeScript declaration for this function? // ./src/fp/addDays
import _addDays from './../add_days/index.js'
const addDays = (b) => (a) => _addDays(a, b)
export default addDays or should it be declared some other way? (like declare module 'date-fns/fp' {
function addDays (number): ((Date | string | number) => (Date))
namespace addDays {}
} or something like this, I don't know) |
Uh I'm not too sure off the top of my head, I will get back to you tomorrow 😃 |
@mattlewis92 thanks 🙂 |
f265d6a
to
1f64bf4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make a(1)(2, 3)
possible.
1717116
to
99d5dc8
Compare
7392ef1
to
0f5d9a7
Compare
I was just typing up this exact feature request when I came across this PR. Thanks for the awesome work y'all are doing! Any idea when v2 will drop? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱😍:shipit:
* Add FP function generation * Modify build_index to build FP index * Add FP typings generator * Regenerate docs, indices, typings and FP * Add FP doc * Add FP CHANGELOG.md entry * Add lodash-fp example * Add FP examples * Remove unused phantomjs-prebuilt * Add FP tests * Fix style * Add ECMAScript Modules documentation article
* Add FP function generation * Modify build_index to build FP index * Add FP typings generator * Regenerate docs, indices, typings and FP * Add FP doc * Add FP CHANGELOG.md entry * Add lodash-fp example * Add FP examples * Remove unused phantomjs-prebuilt * Add FP tests * Fix style * Add ECMAScript Modules documentation article
* Add FP function generation * Modify build_index to build FP index * Add FP typings generator * Regenerate docs, indices, typings and FP * Add FP doc * Add FP CHANGELOG.md entry * Add lodash-fp example * Add FP examples * Remove unused phantomjs-prebuilt * Add FP tests * Fix style * Add ECMAScript Modules documentation article
* Add FP function generation * Modify build_index to build FP index * Add FP typings generator * Regenerate docs, indices, typings and FP * Add FP doc * Add FP CHANGELOG.md entry * Add lodash-fp example * Add FP examples * Remove unused phantomjs-prebuilt * Add FP tests * Fix style * Add ECMAScript Modules documentation article
* Add FP function generation * Modify build_index to build FP index * Add FP typings generator * Regenerate docs, indices, typings and FP * Add FP doc * Add FP CHANGELOG.md entry * Add lodash-fp example * Add FP examples * Remove unused phantomjs-prebuilt * Add FP tests * Fix style * Add ECMAScript Modules documentation article
* Add FP function generation * Modify build_index to build FP index * Add FP typings generator * Regenerate docs, indices, typings and FP * Add FP doc * Add FP CHANGELOG.md entry * Add lodash-fp example * Add FP examples * Remove unused phantomjs-prebuilt * Add FP tests * Fix style * Add ECMAScript Modules documentation article
No description provided.