How to write use API methods from other library in Javascript in Purescript?

Hi I am new to Purescript and I want to write a PostCSS plugin with it. As this plugin will need to interact with the API of PostCSS, which is in Javascript, how can I use those method in Purescript? For example, I want to use their root.walkDecls method in my code.

Have a read of this to get started: https://github.com/purescript/documentation/blob/master/guides/FFI.md

2 Likes

You’ll have to use the FFI for that. I’ll send a few links later that will teach you how to use it.

2 Likes
  • See the link that @afc posted above.

  • I encourage you to read the PureScript book if you are a beginner to PureScript. Chapter 10 is specifically about FFI, but I encourage you to start from the beginning if you aren’t in a hurry (that may not apply to you if you already know Haskell).

  • I also encourage you to read @JordanMartinez’s PureScript reference. Along with the PureScript book, these are some of the highest quality resources in the whole ecosystem. Again, if you’re in a hurry, you can go to the FFI section directly, but unless you know some Haskell, you’ll have a hard time understanding.

2 Likes

Thank you! This is really helpful

Thank you! I will try and read them all. FP is always hard to understand in the beginning but a joy in the end. :grinning:

2 Likes