web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.9 KiB

  1. # filesize.js
  2. [![build status](https://secure.travis-ci.org/avoidwork/filesize.js.svg)](http://travis-ci.org/avoidwork/filesize.js) [![downloads](https://img.shields.io/npm/dt/filesize.svg)](https://www.npmjs.com/package/filesize) [![CDNJS version](https://img.shields.io/cdnjs/v/filesize.svg)](https://cdnjs.com/libraries/filesize)
  3. filesize.js provides a simple way to get a human readable file size string from a number (float or integer) or string.
  4. ## Optional settings
  5. `filesize()` accepts an optional descriptor Object as a second argument, so you can customize the output.
  6. ### base
  7. _*(number)*_ Number base, default is `2`
  8. ### bits
  9. _*(boolean)*_ Enables `bit` sizes, default is `false`
  10. ### exponent
  11. _*(number)*_ Specifies the symbol via exponent, e.g. `2` is `MB` for base 2, default is `-1`
  12. ### fullform
  13. _*(boolean)*_ Enables full form of unit of measure, default is `false`
  14. ### fullforms
  15. _*(array)*_ Array of full form overrides, default is `[]`
  16. ### locale (overrides 'separator')
  17. _*(string || boolean)*_ BCP 47 language tag to specify a locale, or `true` to use default locale, default is `""`
  18. ### localeOptions (overrides 'separator', requires string for 'locale' option)
  19. _*(object)*_ Dictionary of options defined by ECMA-402 ([Number.prototype.toLocaleString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)). Requires locale option to be explicitly passed as a string, otherwise is ignored.
  20. ### output
  21. _*(string)*_ Output of function (`array`, `exponent`, `object`, or `string`), default is `string`
  22. ### round
  23. _*(number)*_ Decimal place, default is `2`
  24. ### separator
  25. _*(string)*_ Decimal separator character, default is `.`
  26. ### spacer
  27. _*(string)*_ Character between the `result` and `symbol`, default is `" "`
  28. ### standard
  29. _*(string)*_ Standard unit of measure, can be `iec` or `jedec`, default is `jedec`; can be overruled by `base`
  30. ### symbols
  31. _*(object)*_ Dictionary of SI/JEDEC/IEC symbols to replace for localization, defaults to english if no match is found
  32. ### unix
  33. _*(boolean)*_ Enables unix style human readable output, e.g `ls -lh`, default is `false`
  34. ## Examples
  35. ```javascript
  36. filesize(500); // "500 B"
  37. filesize(500, {bits: true}); // "4 Kb"
  38. filesize(265318, {base: 10}); // "265.32 kB"
  39. filesize(265318); // "259.1 KB"
  40. filesize(265318, {round: 0}); // "259 KB"
  41. filesize(265318, {output: "array"}); // [259.1, "KB"]
  42. filesize(265318, {output: "object"}); // {value: 259.1, symbol: "KB", exponent: 1}
  43. filesize(1, {symbols: {B: "Б"}}); // "1 Б"
  44. filesize(1024); // "1 KB"
  45. filesize(1024, {exponent: 0}); // "1024 B"
  46. filesize(1024, {output: "exponent"}); // 1
  47. filesize(265318, {standard: "iec"}); // "259.1 KiB"
  48. filesize(265318, {standard: "iec", fullform: true}); // "259.1 kibibytes"
  49. filesize(12, {fullform: true, fullforms: ["байтов"]}); // "12 байтов"
  50. filesize(265318, {separator: ","}); // "259,1 KB"
  51. filesize(265318, {locale: "de"}); // "259,1 KB"
  52. ```
  53. ## Partial Application
  54. `filesize.partial()` takes the second parameter of `filesize()` and returns a new function with the configuration applied
  55. upon execution. This can be used to reduce `Object` creation if you call `filesize()` without caching the `descriptor`
  56. in lexical scope.
  57. ```javascript
  58. const size = filesize.partial({standard: "iec"});
  59. size(265318); // "259.1 KiB"
  60. ```
  61. ## How can I load filesize.js?
  62. filesize.js supports AMD loaders (require.js, curl.js, etc.), node.js & npm (```npm install filesize```), or using a script tag.
  63. An ES6 version is bundled with an npm install, but requires you load it with the full path, e.g. `require(path.join(__dirname, 'node_modules', 'filesize', 'lib', 'filesize.es6.js'))`.
  64. ## License
  65. Copyright (c) 2019 Jason Mulligan
  66. Licensed under the BSD-3 license.