Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simonalling/lines-unlines
Haskell's lines and unlines in TypeScript
https://github.com/simonalling/lines-unlines
Last synced: about 2 months ago
JSON representation
Haskell's lines and unlines in TypeScript
- Host: GitHub
- URL: https://github.com/simonalling/lines-unlines
- Owner: SimonAlling
- License: mit
- Created: 2019-07-29T16:45:35.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T05:42:29.000Z (about 2 years ago)
- Last Synced: 2024-04-24T21:21:58.627Z (9 months ago)
- Language: TypeScript
- Homepage:
- Size: 770 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lines-unlines
Haskell's [`lines`][haskell-lines] and [`unlines`][haskell-unlines] in TypeScript.
[![NPM Version][shield-npm]][npm-url]
[![Downloads Stats][shield-downloads]][npm-url]## Installation
```
npm install --save lines-unlines
```## Usage
```typescript
import { lines, unlines } from "lines-unlines";lines("one\ntwo\n"); // ["one","two"]
unlines(["one", "two"]); // "one\ntwo\n"
```For details, refer to [the Haskell documentation][haskell-lines].
Note in particular that `lines` is _not_ the same function as `_ => _.split("\n")`, and `unlines` is _not_ the same as `_ => _.join("\n")`.Note also that, strictly speaking, neither `lines` nor `unlines` is the other's inverse, even though Hackage (as of 2019‑07‑26) says that "`unlines` is an inverse operation to `lines`".
For example, `unlines (lines "a")` evaluates to `"a\n"`, and `lines (unlines ["\n"])` evaluates to `["", ""]`.## Contribute
`npm run verify` lints, builds and tests the package.
Test cases can be generated using GHCi* (Haskell's REPL, included in the [Haskell Platform](https://www.haskell.org/downloads/)):
```
$ ghci Spec.hs
*Main> spec lines ["", "one"]
*Main> spec unlines [[], ["one"]]
```The output can then be pasted into `index.test.ts`.
* If you have the [Nix package manager](https://nixos.org/nix/), you can run `nix-shell` to get a shell with `ghci` on the path.
[haskell-lines]: http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-String.html#v:lines
[haskell-unlines]: http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-String.html#v:unlines[npm-url]: https://npmjs.org/package/lines-unlines
[shield-npm]: https://img.shields.io/npm/v/lines-unlines.svg
[shield-downloads]: https://img.shields.io/npm/dm/lines-unlines.svg