Comparing version 1.0.0-alpha-03 to 1.0.0-alpha-04
103
lib/fs.js
@@ -20,3 +20,3 @@ // Generated by CoffeeScript 1.8.0 | ||
describe("File system functions", function(context) { | ||
var chdir, exists, read, read_stream, readdir, rm, rmdir, stat, write; | ||
var chdir, exists, lines, read, read_block, read_stream, readdir, rm, rmdir, stat, write; | ||
stat = function(path) { | ||
@@ -60,27 +60,92 @@ return fs(function(_arg) { | ||
}); | ||
read_stream = (function(_arg) { | ||
var promise; | ||
promise = _arg.promise; | ||
read_stream = function(stream) { | ||
var buffer, promise; | ||
promise = require("when").promise; | ||
buffer = ""; | ||
return promise(function(resolve, reject) { | ||
stream.on("data", function(data) { | ||
return buffer += data.toString(); | ||
}); | ||
stream.on("end", function() { | ||
return resolve(buffer); | ||
}); | ||
return stream.on("error", function(error) { | ||
return reject(error); | ||
}); | ||
}); | ||
}; | ||
context.test("read_stream", function() { | ||
return (function*(lines) { | ||
var Readable, promise, stream; | ||
Readable = require("stream").Readable; | ||
stream = new Readable; | ||
promise = read(stream); | ||
stream.push("one\n"); | ||
stream.push("two\n"); | ||
stream.push("three\n"); | ||
stream.push(null); | ||
lines = ((yield promise)).split("\n"); | ||
assert(lines.length === 3); | ||
return assert(lines[0] === "one"); | ||
})(lines); | ||
}); | ||
lines = function(stream) { | ||
return (require("byline"))(stream); | ||
}; | ||
read_block = (function(_arg) { | ||
var promise, reject, resolve; | ||
promise = _arg.promise, reject = _arg.reject, resolve = _arg.resolve; | ||
return function(stream) { | ||
var buffer; | ||
buffer = ""; | ||
return promise(function(resolve, reject) { | ||
return (function(pending, resolved, _resolve, _reject) { | ||
_resolve = function(x) { | ||
if (pending.length === 0) { | ||
return resolved.push(resolve(x)); | ||
} else { | ||
return pending.shift().resolve(x); | ||
} | ||
}; | ||
_reject = function(x) { | ||
if (pending.length === 0) { | ||
return resolved.push(reject(x)); | ||
} else { | ||
return pending.shift().reject(x); | ||
} | ||
}; | ||
stream.on("data", function(data) { | ||
return buffer += data.toString(); | ||
return _resolve(data.toString()); | ||
}); | ||
stream.on("end", function() { | ||
return resolve(buffer); | ||
return _resolve(null); | ||
}); | ||
return stream.on("error", function(error) { | ||
return reject(error); | ||
stream.on("error", function() { | ||
return _reject(error); | ||
}); | ||
}); | ||
return function() { | ||
if (resolved.length === 0) { | ||
return promise(function(resolve, reject) { | ||
return pending.push({ | ||
resolve: resolve, | ||
reject: reject | ||
}); | ||
}); | ||
} else { | ||
return resolved.shift(); | ||
} | ||
}; | ||
})([], [], null, null); | ||
}; | ||
})(require("when")); | ||
context.test("read_stream", function*() { | ||
var createReadStream, lines; | ||
createReadStream = require("fs").createReadStream; | ||
lines = ((yield read_stream(createReadStream("test/lines.txt")))).trim().split("\n"); | ||
assert(lines.length === 3); | ||
return assert(lines[0] === "one"); | ||
context.test("read_block", function() { | ||
var Readable; | ||
Readable = require("stream").Readable; | ||
return (function*(stream) { | ||
var _stream; | ||
stream.push("one\n"); | ||
stream.push("two\n"); | ||
stream.push("three\n"); | ||
_stream = lines(stream); | ||
assert(((yield read_block(_stream))) === "one"); | ||
assert(((yield read_block(_stream))) === "two"); | ||
return assert(((yield read_block(_stream))) === "three"); | ||
})(new Readable); | ||
}); | ||
@@ -140,2 +205,4 @@ write = function(path, content) { | ||
read_stream: read_stream, | ||
lines: lines, | ||
read_block: read_block, | ||
readdir: readdir, | ||
@@ -142,0 +209,0 @@ stat: stat, |
@@ -8,3 +8,3 @@ // Generated by CoffeeScript 1.8.0 | ||
describe("General functions", function(context) { | ||
var abort, include, memoize, shell, sleep, timer; | ||
var abort, curry, include, memoize, shell, sleep, timer, times; | ||
abort = function() { | ||
@@ -68,5 +68,22 @@ return process.exit(-1); | ||
context.test("shell", function*() { | ||
return assert(((yield shell("ls ./test"))).stdout.trim().split("\n").length === 4); | ||
return assert(((yield shell("ls ./test"))).stdout.trim().split("\n").length === 5); | ||
}); | ||
curry = require("./core").curry; | ||
times = curry(function(fn, n) { | ||
var _results; | ||
_results = []; | ||
while (n-- !== 0) { | ||
_results.push(fn()); | ||
} | ||
return _results; | ||
}); | ||
context.test("times", function() { | ||
return (function(n) { | ||
return assert((times((function() { | ||
return ++n; | ||
}), 3)).length === 3); | ||
})(0); | ||
}); | ||
module.exports = { | ||
times: times, | ||
shell: shell, | ||
@@ -73,0 +90,0 @@ sleep: sleep, |
{ | ||
"name": "fairmont", | ||
"version": "1.0.0-alpha-03", | ||
"version": "1.0.0-alpha-04", | ||
"description": "A collection of useful functions and utilities.", | ||
@@ -34,2 +34,3 @@ "files": [ | ||
"dependencies": { | ||
"byline": "^4.2.1", | ||
"when": "^3.7.2" | ||
@@ -36,0 +37,0 @@ }, |
# Fairmont | ||
A collection of useful CoffeeScript/JavaScript functions. These include functions to help with functional programming, arrays, objects, and more. It's intended as an alternative to Underscore. | ||
A collection of useful CoffeeScript/JavaScript functions. These include functions to help with functional programming, arrays, objects, and more. Fairmont is inspired by [Underscore][100], [EssentialJS][110], and [prelude.coffee][120]. | ||
## Core Functions | ||
[100]:http://underscorejs.org/ | ||
[110]:https://github.com/elclanrs/essential.js | ||
[120]:http://xixixao.github.io/prelude-ls/ | ||
## Why Fairmont? | ||
Fairmont offers a combination of features we couldn't find in existing libraries: | ||
* Functional programming friendly | ||
* ES6 aware (in particular, uses promises and generators for async operations) | ||
* Comprehensive | ||
Fairmont is also a literate programming project—the documentation, code, examples, and tests are together, making it easy to see what a function does, how it does it, and why it does it that particular way. | ||
### Functional Programming Friendly | ||
Fairmont is built on a functional programming foundation, including implementations for currying, partial application, and composition. Most functions are curried by default and designed with composition in mind. | ||
### ES6 Aware | ||
Fairmont wraps common asynchronous operations so they can be used in `yield` expressions. For example, here's how you can read a file using Fairmont. | ||
```coffee | ||
content = yield read "war-and-peace.txt" | ||
``` | ||
### Comprehensive | ||
One of the nice things about Underscore is that it offers a lot of useful functions. Many common tasks can be written entirely using Underscore functions. Fairmont has a similar ambition. While there's nothing wrong with specialized libraries, there are times when you just want a good Swiss Army Knife. | ||
## List of Functions | ||
### Core Functions | ||
* [API Reference][core] | ||
@@ -15,3 +47,3 @@ | ||
## Logical Functions | ||
### Logical Functions | ||
@@ -25,3 +57,3 @@ * [API Reference][logical] | ||
## Numeric Functions | ||
### Numeric Functions | ||
@@ -36,3 +68,3 @@ * [API Reference][numeric] | ||
## Type Functions | ||
### Type Functions | ||
@@ -46,3 +78,3 @@ * [API Reference][core] | ||
## Array functions | ||
### Array functions | ||
@@ -58,3 +90,3 @@ * [API Reference][array] | ||
## Crypto Functions | ||
### Crypto Functions | ||
@@ -68,3 +100,3 @@ * [API Reference][crypto] | ||
## File System Functions | ||
### File System Functions | ||
@@ -78,3 +110,3 @@ * [API Reference][fs] | ||
## Object Functions | ||
### Object Functions | ||
@@ -88,3 +120,3 @@ * [API Reference][object] | ||
## String Functions | ||
### String Functions | ||
@@ -99,3 +131,3 @@ * [API Reference][string] | ||
## Miscellaneous Functions | ||
### Miscellaneous Functions | ||
@@ -108,1 +140,21 @@ * [API Reference][misc] | ||
[misc]:src/index.litcoffee | ||
## Status | ||
Fairmont is still under heavy development and is `alpha` quality, meaning you should probably not use it in your production code. | ||
## Roadmap | ||
You can get an idea of what we're planning by looking at the [issues list][200]. If you want something that isn't there, and you think it would be a good addition, please open a ticket. | ||
[200]:https://github.com/pandastrike/fairmont/issues | ||
Our overarching goals for the project include: | ||
* Making the library more comprehensive | ||
* Improving the tests and documentation | ||
* Ensuring that we can use an FP style in real-world scenarios | ||
* Introducing an idiom for supporting lazy evaluation |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67999
1230
151
1
2
+ Addedbyline@^4.2.1
+ Addedbyline@4.2.2(transitive)