Skip to content

Commit cc64bcb

Browse files
Merge pull request #294 from davidchambers/typescript
derive index.js and index.d.ts from canonical list of method names
2 parents 8cf6a3a + ee102dc commit cc64bcb

File tree

7 files changed

+87
-0
lines changed

7 files changed

+87
-0
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@
22

33
Additions and modifications to the specification are best proposed in issues.
44
If there is support for a proposal, the next step is to submit a pull request.
5+
6+
When adding a type class to __README.md__, please update __names__ then run:
7+
8+
```console
9+
$ npm run generate-js
10+
$ npm run generate-ts
11+
```

index.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export const equals: 'fantasy-land/equals';
2+
export const lte: 'fantasy-land/lte';
3+
export const compose: 'fantasy-land/compose';
4+
export const id: 'fantasy-land/id';
5+
export const concat: 'fantasy-land/concat';
6+
export const empty: 'fantasy-land/empty';
7+
export const invert: 'fantasy-land/invert';
8+
export const filter: 'fantasy-land/filter';
9+
export const map: 'fantasy-land/map';
10+
export const contramap: 'fantasy-land/contramap';
11+
export const ap: 'fantasy-land/ap';
12+
export const of: 'fantasy-land/of';
13+
export const alt: 'fantasy-land/alt';
14+
export const zero: 'fantasy-land/zero';
15+
export const reduce: 'fantasy-land/reduce';
16+
export const traverse: 'fantasy-land/traverse';
17+
export const chain: 'fantasy-land/chain';
18+
export const chainRec: 'fantasy-land/chainRec';
19+
export const extend: 'fantasy-land/extend';
20+
export const extract: 'fantasy-land/extract';
21+
export const bimap: 'fantasy-land/bimap';
22+
export const promap: 'fantasy-land/promap';

names

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
equals
2+
lte
3+
compose
4+
id
5+
concat
6+
empty
7+
invert
8+
filter
9+
map
10+
contramap
11+
ap
12+
of
13+
alt
14+
zero
15+
reduce
16+
traverse
17+
chain
18+
chainRec
19+
extend
20+
extract
21+
bimap
22+
promap

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929
"files": [
3030
"/LICENSE",
3131
"/README.md",
32+
"/index.d.ts",
3233
"/index.js",
3334
"/package.json"
3435
],
3536
"main": "index.js",
37+
"types": "index.d.ts",
3638
"scripts": {
3739
"doctest": "sanctuary-doctest",
40+
"generate-js": "scripts/generate-js",
41+
"generate-ts": "scripts/generate-ts",
3842
"lint": "sanctuary-lint",
3943
"release": "sanctuary-release",
4044
"test": "npm run lint && sanctuary-test && npm run doctest"

scripts/generate-js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -euf -o pipefail
3+
4+
cat >index.js <<EOF
5+
(function() {
6+
7+
'use strict';
8+
9+
var mapping = {
10+
$(awk '{ printf (NR > 1 ? ",\n " : "") $0 ": \047fantasy-land/" $0 "\047" }' names)
11+
};
12+
13+
/* istanbul ignore else */
14+
if (typeof module === 'object' && typeof module.exports === 'object') {
15+
module.exports = mapping;
16+
} else {
17+
self.FantasyLand = mapping;
18+
}
19+
20+
} ());
21+
EOF

scripts/generate-ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -euf -o pipefail
3+
4+
awk '{ print "export const " $0 ": \047fantasy-land/" $0 "\047;" }' names >index.d.ts

scripts/lint

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
set -euf -o pipefail
3+
4+
node_modules/.bin/sanctuary-lint "$@"
5+
6+
scripts/generate-js && git diff --exit-code index.js
7+
scripts/generate-ts && git diff --exit-code index.d.ts

0 commit comments

Comments
 (0)