Skip to content

Commit 4ac5033

Browse files
author
David Chase
committed
add dist folder, add rollup for es6 import/export, add buba for tests, re-config structure
1 parent 5cf8d0f commit 4ac5033

File tree

7 files changed

+74
-41
lines changed

7 files changed

+74
-41
lines changed

dist/path-union.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
var _compose = function (f, g) { return function () {
4+
var args = [], len = arguments.length;
5+
while ( len-- ) args[ len ] = arguments[ len ];
6+
7+
return f(g.apply(void 0, args));
8+
; } }
9+
10+
var uniq = function (xs) { return xs.reduce(function (list, x) { return list.indexOf(x) === -1 ? list.concat(x) : list; }, []); }
11+
12+
var concat = function (xs, list) { return xs.concat(list); }
13+
14+
var compose = function (fns) { return fns.reduce(_compose); }
15+
16+
var union = compose([uniq, concat])
17+
18+
var join = function (separator) { return function (xs) { return xs.join(separator); }; }
19+
20+
var split = function (separator) { return function (str) { return str.split(separator); }; }
21+
22+
var chain = function (fn) { return function (xs) { return [].concat.apply([], xs.map(fn)); }; }
23+
24+
var of = Array.of.bind(Array)
25+
26+
var filter = function (pred) { return function (xs) { return xs.filter(pred); }; }
27+
28+
var prepend = function (a) { return function (b) { return a.concat(b); }; }
29+
30+
var index = compose([prepend('/'), join('/'), filter(Boolean), union, chain(split('/')), of])
31+
32+
module.exports = index;

dist/path-union.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
'use strict'
2-
module.exports = require('./prelude').pathUnion
1+
import {compose, prepend, join, filter, union, chain, split, of} from './prelude'
2+
3+
export default compose([prepend('/'), join('/'), filter(Boolean), union, chain(split('/')), of])

package.json

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
{
22
"name": "path-union",
3-
"version": "1.0.1",
43
"description": "Create a union between two paths",
5-
"main": "index.js",
6-
"scripts": {
7-
"test": "tape test.js | tap-spec"
8-
},
9-
"repository": {
10-
"type": "git",
11-
"url": "git+https://github.com/davidchase/path-union.git"
12-
},
13-
"keywords": [
14-
"path",
15-
"union",
16-
"functional"
17-
],
4+
"version": "1.0.1",
185
"author": "David Chase <davidchase03@gmail.com>",
19-
"license": "MIT",
206
"bugs": {
217
"url": "https://github.com/davidchase/path-union/issues"
228
},
23-
"homepage": "https://github.com/davidchase/path-union#readme",
249
"devDependencies": {
10+
"buba": "1.0.6",
11+
"rollup-plugin-buble": "0.12.1",
2512
"tap-spec": "4.1.1",
2613
"tape": "4.6.0"
14+
},
15+
"homepage": "https://github.com/davidchase/path-union#readme",
16+
"keywords": [
17+
"functional",
18+
"path",
19+
"union"
20+
],
21+
"license": "MIT",
22+
"main": "dist/path-union.js",
23+
"repository": {
24+
"type": "git",
25+
"url": "git+https://github.com/davidchase/path-union.git"
26+
},
27+
"scripts": {
28+
"build": "mkdir -p dist && rollup -c",
29+
"test": "tape --require buba test.js | tap-spec"
2730
}
2831
}

prelude.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
'use strict'
22

3-
const _compose = function _compose(f, g) {
4-
return function () {
5-
return f(g.apply(null, arguments));
6-
};
7-
};
8-
9-
const compose = fns => fns.reduce(_compose)
3+
const _compose = (f, g) => (...args) => f(g(...args))
104

115
const uniq = xs => xs.reduce((list, x) => list.indexOf(x) === -1 ? list.concat(x) : list, [])
126

13-
const identity = x => x
14-
157
const concat = (xs, list) => xs.concat(list)
168

17-
const union = compose([uniq, concat])
18-
19-
const join = separator => xs => xs.join(separator)
9+
export const compose = fns => fns.reduce(_compose)
2010

21-
const split = separator => str => str.split(separator)
11+
export const union = compose([uniq, concat])
2212

23-
const chain = fn => xs => [].concat.apply([], xs.map(fn))
13+
export const join = separator => xs => xs.join(separator)
2414

25-
const of = Array.of.bind(Array)
15+
export const split = separator => str => str.split(separator)
2616

27-
const filter = pred => xs => xs.filter(pred)
17+
export const chain = fn => xs => [].concat.apply([], xs.map(fn))
2818

29-
const prepend = a => b => a.concat(b)
19+
export const of = Array.of.bind(Array)
3020

31-
const pathUnion = compose([prepend('/'), join('/'), filter(Boolean), union, chain(split('/')), of])
21+
export const filter = pred => xs => xs.filter(pred)
3222

33-
exports.pathUnion = pathUnion
23+
export const prepend = a => b => a.concat(b)

rollup.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import buble from 'rollup-plugin-buble'
2+
export default {
3+
entry: 'index.js',
4+
dest: 'dist/path-union.js',
5+
plugins: [ buble() ],
6+
format: 'cjs'
7+
};

test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use strict'
22

3-
const test = require('tape')
4-
const path = require('path')
5-
const union = require('./index')
6-
3+
import test from 'tape'
4+
import path from 'path'
5+
import union from './index'
76

87
test('it works', function(t){
98
const expected = path.join(__dirname, 'output/src/images')

0 commit comments

Comments
 (0)