This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Devin <[email protected]>
- Loading branch information
Devin
committed
Jul 15, 2015
1 parent
75d0fde
commit b9ffa4f
Showing
9 changed files
with
77 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
/* | ||
* Q.js for Node | ||
* author:[email protected] | ||
* update:2014/09/18 15:33 | ||
* update:2015/07/15 10:19 | ||
*/ | ||
(function (global, undefined) { | ||
(function (undefined) { | ||
"use strict"; | ||
|
||
var toString = Object.prototype.toString, | ||
|
@@ -36,6 +36,8 @@ | |
//扩展对象 | ||
//forced:是否强制扩展 | ||
function extend(destination, source, forced) { | ||
if (!destination || !source) return; | ||
|
||
for (var key in source) { | ||
if (key == undefined || !has.call(source, key)) continue; | ||
|
||
|
@@ -99,7 +101,7 @@ | |
} | ||
|
||
if (level && size < stepNow) { | ||
stepNow /= (isNum ? steps : steps[steps.length - 1]); | ||
stepNow /= (isNum ? steps : steps.last()); | ||
level--; | ||
} | ||
|
||
|
@@ -110,22 +112,24 @@ | |
|
||
//格式化数字输出,将数字转为合适的单位输出,默认按照1024层级转为文件单位输出 | ||
function formatSize(size, ops) { | ||
ops = ops || {}; | ||
ops = ops === true ? { all: true } : ops || {}; | ||
|
||
if (isNaN(size) || size == undefined || size < 0) return { text: ops.error || "--" }; | ||
if (isNaN(size) || size == undefined || size < 0) { | ||
var error = ops.error || "--"; | ||
|
||
var pl = parseLevel(size, ops.steps, ops.limit), | ||
return ops.all ? { text: error } : error; | ||
} | ||
|
||
digit = ops.digit, | ||
var pl = parseLevel(size, ops.steps, ops.limit), | ||
|
||
value = pl.value, | ||
text = value.toFixed(isUInt(digit) || digit == 0 ? digit : 2); | ||
text = value.toFixed(def(ops.digit, 2)); | ||
|
||
if (ops.trim !== false && text.lastIndexOf(".") != -1) text = text.replace(/\.?0+$/, ""); | ||
|
||
pl.text = text + (ops.join || "") + (ops.units || UNITS_FILE_SIZE)[pl.level + (ops.levelFix || 0)]; | ||
pl.text = text + (ops.join || "") + (ops.units || UNITS_FILE_SIZE)[pl.level + (ops.start || 0)]; | ||
|
||
return pl; | ||
return ops.all ? pl : pl.text; | ||
} | ||
|
||
//---------------------- export ---------------------- | ||
|
@@ -145,10 +149,8 @@ | |
formatSize: formatSize | ||
}; | ||
|
||
global.Q = Q; | ||
|
||
if (typeof module === "object" && typeof module.exports === "object") { | ||
module.exports = Q; | ||
} | ||
|
||
})(this); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.