Skip to content

Commit

Permalink
Simplifying filesize.partial() & adding a test
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Jan 21, 2017
1 parent 245aa6d commit 4d1e9ea
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/filesize.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2017 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 3.4.1
* @version 3.4.2
*/
(function (global) {
const b = /^(b|B)$/,
Expand Down Expand Up @@ -121,7 +121,7 @@
}

// Partial application for functional programming
filesize.partial = (descriptor = {}) => arg => filesize(arg, descriptor);
filesize.partial = opt => arg => filesize(arg, opt);

// CommonJS, AMD, script tag
if (typeof exports !== "undefined") {
Expand Down
7 changes: 3 additions & 4 deletions lib/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @copyright 2017 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 3.4.1
* @version 3.4.2
*/
(function (global) {
var b = /^(b|B)$/,
Expand Down Expand Up @@ -136,10 +136,9 @@
}

// Partial application for functional programming
filesize.partial = function () {
var descriptor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
filesize.partial = function (opt) {
return function (arg) {
return filesize(arg, descriptor);
return filesize(arg, opt);
};
};

Expand Down
4 changes: 2 additions & 2 deletions lib/filesize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/filesize.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "filesize",
"description": "JavaScript library to generate a human readable String describing the file size",
"version": "3.4.1",
"version": "3.4.2",
"homepage": "http://filesizejs.com",
"author": "Jason Mulligan <jason.mulligan@avoidwork.com>",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@
}

// Partial application for functional programming
filesize.partial = (descriptor = {}) => arg => filesize(arg, descriptor);
filesize.partial = opt => arg => filesize(arg, opt);
12 changes: 10 additions & 2 deletions test/filesize_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,25 @@ exports["filesize"] = {
suffixes: function (test) {
test.expect(2);

test.equal(filesize(this.byte, {suffixes: {B: "Б"}}), "1 Б", "Should be '1 Б'");
test.equal(filesize(this.byte, {suffixes: {B: "Б"}}), "1 Б", "Should be '1 Б'");
test.equal(filesize(this.kilobyte, {suffixes: {B: "Б"}}), "1 KB", "Should be '1 KB'");

test.done();
},
symbols: function (test) {
test.expect(2);

test.equal(filesize(this.byte, {symbols: {B: "Б"}}), "1 Б", "Should be '1 Б'");
test.equal(filesize(this.byte, {symbols: {B: "Б"}}), "1 Б", "Should be '1 Б'");
test.equal(filesize(this.kilobyte, {symbols: {B: "Б"}}), "1 KB", "Should be '1 KB'");

test.done();
},
partial: function (test) {
test.expect(1);
test.size = filesize.partial({exponent: 0});

test.equal(test.size(this.kilobyte), "1024 B", "Should be '1024 B'");

test.done();
}
};

0 comments on commit 4d1e9ea

Please sign in to comment.