Skip to content

Commit 4d1e9ea

Browse files
committed
Simplifying filesize.partial() & adding a test
1 parent 245aa6d commit 4d1e9ea

7 files changed

+20
-13
lines changed

lib/filesize.es6.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @copyright 2017 Jason Mulligan <[email protected]>
55
* @license BSD-3-Clause
6-
* @version 3.4.1
6+
* @version 3.4.2
77
*/
88
(function (global) {
99
const b = /^(b|B)$/,
@@ -121,7 +121,7 @@
121121
}
122122

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

126126
// CommonJS, AMD, script tag
127127
if (typeof exports !== "undefined") {

lib/filesize.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @copyright 2017 Jason Mulligan <[email protected]>
77
* @license BSD-3-Clause
8-
* @version 3.4.1
8+
* @version 3.4.2
99
*/
1010
(function (global) {
1111
var b = /^(b|B)$/,
@@ -136,10 +136,9 @@
136136
}
137137

138138
// Partial application for functional programming
139-
filesize.partial = function () {
140-
var descriptor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
139+
filesize.partial = function (opt) {
141140
return function (arg) {
142-
return filesize(arg, descriptor);
141+
return filesize(arg, opt);
143142
};
144143
};
145144

lib/filesize.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/filesize.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "filesize",
33
"description": "JavaScript library to generate a human readable String describing the file size",
4-
"version": "3.4.1",
4+
"version": "3.4.2",
55
"homepage": "http://filesizejs.com",
66
"author": "Jason Mulligan <[email protected]>",
77
"repository": {

src/filesize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@
101101
}
102102

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

test/filesize_test.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,25 @@ exports["filesize"] = {
123123
suffixes: function (test) {
124124
test.expect(2);
125125

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

129129
test.done();
130130
},
131131
symbols: function (test) {
132132
test.expect(2);
133133

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

137+
test.done();
138+
},
139+
partial: function (test) {
140+
test.expect(1);
141+
test.size = filesize.partial({exponent: 0});
142+
143+
test.equal(test.size(this.kilobyte), "1024 B", "Should be '1024 B'");
144+
137145
test.done();
138146
}
139147
};

0 commit comments

Comments
 (0)