Commit f064c792 authored by Muddsair Sharif's avatar Muddsair Sharif
Browse files

Initial commit

parents
Pipeline #8 canceled with stages
{
"decimal": ",",
"thousands": "\u00a0",
"grouping": [3],
"currency": ["", "$"]
}
{
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["", "\u00a0€"],
"percent": "\u202f%"
}
{
"decimal": ".",
"thousands": ",",
"grouping": [3],
"currency": ["₪", ""]
}
{
"decimal": ",",
"thousands": "\u00a0",
"grouping": [3],
"currency": ["", "\u00a0Ft"]
}
{
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["€", ""]
}
{
"decimal": ".",
"thousands": ",",
"grouping": [3],
"currency": ["", "円"]
}
{
"decimal": ".",
"thousands": ",",
"grouping": [3],
"currency": ["₩", ""]
}
{
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["", "\u00a0ден."]
}
{
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["€\u00a0", ""]
}
{
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["", "zł"]
}
{
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["R$", ""]
}
{
"decimal": ",",
"thousands": "\u00a0",
"grouping": [3],
"currency": ["", "\u00a0руб."]
}
{
"decimal": ",",
"thousands": "\u00a0",
"grouping": [3],
"currency": ["", "SEK"]
}
{
"decimal": ",",
"thousands": "\u00a0",
"grouping": [3],
"currency": ["", "\u00a0₴."]
}
{
"decimal": ".",
"thousands": ",",
"grouping": [3],
"currency": ["¥", ""]
}
{
"_args": [
[
{
"raw": "d3-format@1.2.0",
"scope": null,
"escapedName": "d3-format",
"name": "d3-format",
"rawSpec": "1.2.0",
"spec": "1.2.0",
"type": "version"
},
"C:\\Users\\Giuliano\\worldwind\\nasaworldwind\\node\\node_modules\\d3"
]
],
"_from": "d3-format@1.2.0",
"_id": "d3-format@1.2.0",
"_inCache": true,
"_location": "/d3-format",
"_nodeVersion": "7.3.0",
"_npmOperationalInternal": {
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/d3-format-1.2.0.tgz_1491245128360_0.3093313854187727"
},
"_npmUser": {
"name": "mbostock",
"email": "mike@ocks.org"
},
"_npmVersion": "3.10.10",
"_phantomChildren": {},
"_requested": {
"raw": "d3-format@1.2.0",
"scope": null,
"escapedName": "d3-format",
"name": "d3-format",
"rawSpec": "1.2.0",
"spec": "1.2.0",
"type": "version"
},
"_requiredBy": [
"/d3",
"/d3-scale"
],
"_resolved": "https://registry.npmjs.org/d3-format/-/d3-format-1.2.0.tgz",
"_shasum": "6b480baa886885d4651dc248a8f4ac9da16db07a",
"_shrinkwrap": null,
"_spec": "d3-format@1.2.0",
"_where": "C:\\Users\\Giuliano\\worldwind\\nasaworldwind\\node\\node_modules\\d3",
"author": {
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"
},
"bugs": {
"url": "https://github.com/d3/d3-format/issues"
},
"dependencies": {},
"description": "Format numbers for human consumption.",
"devDependencies": {
"d3-queue": "3",
"eslint": "3",
"package-preamble": "0.0",
"rollup": "0.41",
"tape": "4",
"uglify-js": "^2.8.11"
},
"directories": {},
"dist": {
"shasum": "6b480baa886885d4651dc248a8f4ac9da16db07a",
"tarball": "https://registry.npmjs.org/d3-format/-/d3-format-1.2.0.tgz"
},
"gitHead": "b1e967616b6a9cdd3111d13cd34528a17fa4a0a3",
"homepage": "https://d3js.org/d3-format/",
"jsnext:main": "index",
"keywords": [
"d3",
"d3-module",
"format",
"localization"
],
"license": "BSD-3-Clause",
"main": "build/d3-format.js",
"maintainers": [
{
"name": "mbostock",
"email": "mike@ocks.org"
}
],
"module": "index",
"name": "d3-format",
"optionalDependencies": {},
"readme": "# d3-format\n\nEver noticed how sometimes JavaScript doesn’t display numbers the way you expect? Like, you tried to print tenths with a simple loop:\n\n```js\nfor (var i = 0; i < 10; i++) {\n console.log(0.1 * i);\n}\n```\n\nAnd you got this:\n\n```js\n0\n0.1\n0.2\n0.30000000000000004\n0.4\n0.5\n0.6000000000000001\n0.7000000000000001\n0.8\n0.9\n```\n\nWelcome to [binary floating point](https://en.wikipedia.org/wiki/Double-precision_floating-point_format)! ಠ_ಠ\n\nYet rounding error is not the only reason to customize number formatting. A table of numbers should be formatted consistently for comparison; above, 0.0 would be better than 0. Large numbers should have grouped digits (e.g., 42,000) or be in scientific or metric notation (4.2e+4, 42k). Currencies should have fixed precision ($3.50). Reported numerical results should be rounded to significant digits (4021 becomes 4000). Number formats should appropriate to the reader’s locale (42.000,00 or 42,000.00). The list goes on.\n\nFormatting numbers for human consumption is the purpose of d3-format, which is modeled after Python 3’s [format specification mini-language](https://docs.python.org/3/library/string.html#format-specification-mini-language) ([PEP 3101](https://www.python.org/dev/peps/pep-3101/)). Revisiting the example above:\n\n```js\nvar f = d3.format(\".1f\");\nfor (var i = 0; i < 10; i++) {\n console.log(f(0.1 * i));\n}\n```\n\nNow you get this:\n\n```js\n0.0\n0.1\n0.2\n0.3\n0.4\n0.5\n0.6\n0.7\n0.8\n0.9\n```\n\nBut d3-format is much more than an alias for [number.toFixed](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)! A few more examples:\n\n```js\nd3.format(\".0%\")(0.123); // rounded percentage, \"12%\"\nd3.format(\"($.2f\")(-3.5); // localized fixed-point currency, \"(£3.50)\"\nd3.format(\"+20\")(42); // space-filled and signed, \" +42\"\nd3.format(\".^20\")(42); // dot-filled and centered, \".........42.........\"\nd3.format(\".2s\")(42e6); // SI-prefix with two significant digits, \"42M\"\nd3.format(\"#x\")(48879); // prefixed lowercase hexadecimal, \"0xbeef\"\nd3.format(\",.2r\")(4223); // grouped thousands with two significant digits, \"4,200\"\n```\n\nSee [*locale*.format](#locale_format) for a detailed specification, and try running [d3.formatSpecifier](#formatSpecifier) on the above formats to decode their meaning.\n\n## Installing\n\nIf you use NPM, `npm install d3-format`. Otherwise, download the [latest release](https://github.com/d3/d3-format/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-format.v1.min.js) or as part of [D3 4.0](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:\n\n```html\n<script src=\"https://d3js.org/d3-format.v1.min.js\"></script>\n<script>\n\nvar format = d3.format(\".2s\");\n\n</script>\n```\n\nLocale files are hosted on [unpkg](https://unpkg.com/) and can be loaded using [d3.json](https://github.com/d3/d3-request/blob/master/README.md#json). For example, to set Russian as the default locale:\n\n```js\nd3.json(\"https://unpkg.com/d3-format@1/locale/ru-RU.json\", function(error, locale) {\n if (error) throw error;\n\n d3.formatDefaultLocale(locale);\n\n var format = d3.format(\"$,\");\n\n console.log(format(1234.56)); // 1 234,56 руб.\n});\n```\n\n[Try d3-format in your browser.](https://tonicdev.com/npm/d3-format)\n\n## API Reference\n\n<a name=\"format\" href=\"#format\">#</a> d3.<b>format</b>(<i>specifier</i>) [<>](https://github.com/d3/d3-format/blob/master/src/defaultLocale.js#L4 \"Source\")\n\nAn alias for [*locale*.format](#locale_format) on the [default locale](#formatDefaultLocale).\n\n<a name=\"formatPrefix\" href=\"#formatPrefix\">#</a> d3.<b>formatPrefix</b>(<i>specifier</i>, <i>value</i>) [<>](https://github.com/d3/d3-format/blob/master/src/defaultLocale.js#L5 \"Source\")\n\nAn alias for [*locale*.formatPrefix](#locale_formatPrefix) on the [default locale](#formatDefaultLocale).\n\n<a name=\"locale_format\" href=\"#locale_format\">#</a> <i>locale</i>.<b>format</b>(<i>specifier</i>) [<>](https://github.com/d3/d3-format/blob/master/src/locale.js#L18 \"Source\")\n\nReturns a new format function for the given string *specifier*. The returned function takes a number as the only argument, and returns a string representing the formatted number. The general form of a specifier is:\n\n```\n[​[fill]align][sign][symbol][0][width][,][.precision][type]\n```\n\nThe *fill* can be any character. The presence of a fill character is signaled by the *align* character following it, which must be one of the following:\n\n* `>` - Forces the field to be right-aligned within the available space. (Default behavior).\n* `<` - Forces the field to be left-aligned within the available space.\n* `^` - Forces the field to be centered within the available space.\n* `=` - like `>`, but with any sign and symbol to the left of any padding.\n\nThe *sign* can be:\n\n* `-` - nothing for positive and a minus sign for negative. (Default behavior.)\n* `+` - a plus sign for positive and a minus sign for negative.\n* `(` - nothing for positive and parentheses for negative.\n* ` ` (space) - a space for positive and a minus sign for negative.\n\nThe *symbol* can be:\n\n* `$` - apply currency symbols per the locale definition.\n* `#` - for binary, octal, or hexadecimal notation, prefix by `0b`, `0o`, or `0x`, respectively.\n\nThe *zero* (`0`) option enables zero-padding; this implicitly sets *fill* to `0` and *align* to `=`. The *width* defines the minimum field width; if not specified, then the width will be determined by the content. The *comma* (`,`) option enables the use of a group separator, such as a comma for thousands.\n\nDepending on the *type*, the *precision* either indicates the number of digits that follow the decimal point (types `f` and `%`), or the number of significant digits (types `​`, `e`, `g`, `r`, `s` and `p`). If the precision is not specified, it defaults to 6 for all types except `​` (none), which defaults to 12. Precision is ignored for integer formats (types `b`, `o`, `d`, `x`, `X` and `c`). See [precisionFixed](#precisionFixed) and [precisionRound](#precisionRound) for help picking an appropriate precision.\n\nThe available *type* values are:\n\n* `e` - exponent notation.\n* `f` - fixed point notation.\n* `g` - either decimal or exponent notation, rounded to significant digits.\n* `r` - decimal notation, rounded to significant digits.\n* `s` - decimal notation with an [SI prefix](#locale_formatPrefix), rounded to significant digits.\n* `%` - multiply by 100, and then decimal notation with a percent sign.\n* `p` - multiply by 100, round to significant digits, and then decimal notation with a percent sign.\n* `b` - binary notation, rounded to integer.\n* `o` - octal notation, rounded to integer.\n* `d` - decimal notation, rounded to integer.\n* `x` - hexadecimal notation, using lower-case letters, rounded to integer.\n* `X` - hexadecimal notation, using upper-case letters, rounded to integer.\n* `c` - converts the integer to the corresponding unicode character before printing.\n* `​` (none) - like `g`, but trim insignificant trailing zeros.\n\nThe type `n` is also supported as shorthand for `,g`. For the `g`, `n` and `​` (none) types, decimal notation is used if the resulting string would have *precision* or fewer digits; otherwise, exponent notation is used. For example:\n\n```js\nd3.format(\".2\")(42); // \"42\"\nd3.format(\".2\")(4.2); // \"4.2\"\nd3.format(\".1\")(42); // \"4e+1\"\nd3.format(\".1\")(4.2); // \"4\"\n```\n\n<a name=\"locale_formatPrefix\" href=\"#locale_formatPrefix\">#</a> <i>locale</i>.<b>formatPrefix</b>(<i>specifier</i>, <i>value</i>) [<>](https://github.com/d3/d3-format/blob/master/src/locale.js#L127 \"Source\")\n\nEquivalent to [*locale*.format](#locale_format), except the returned function will convert values to the units of the appropriate [SI prefix](https://en.wikipedia.org/wiki/Metric_prefix#List_of_SI_prefixes) for the specified numeric reference *value* before formatting in fixed point notation. The following prefixes are supported:\n\n* `y` - yocto, 10⁻²⁴\n* `z` - zepto, 10⁻²¹\n* `a` - atto, 10⁻¹⁸\n* `f` - femto, 10⁻¹⁵\n* `p` - pico, 10⁻¹²\n* `n` - nano, 10⁻⁹\n* `µ` - micro, 10⁻⁶\n* `m` - milli, 10⁻³\n* `​` (none) - 10⁰\n* `k` - kilo, 10³\n* `M` - mega, 10⁶\n* `G` - giga, 10⁹\n* `T` - tera, 10¹²\n* `P` - peta, 10¹⁵\n* `E` - exa, 10¹⁸\n* `Z` - zetta, 10²¹\n* `Y` - yotta, 10²⁴\n\nUnlike [*locale*.format](#locale_format) with the `s` format type, this method returns a formatter with a consistent SI prefix, rather than computing the prefix dynamically for each number. In addition, the *precision* for the given *specifier* represents the number of digits past the decimal point (as with `f` fixed point notation), not the number of significant digits. For example:\n\n```js\nvar f = d3.formatPrefix(\",.0\", 1e-6);\nf(0.00042); // \"420µ\"\nf(0.0042); // \"4,200µ\"\n```\n\nThis method is useful when formatting multiple numbers in the same units for easy comparison. See [precisionPrefix](#precisionPrefix) for help picking an appropriate precision, and [bl.ocks.org/9764126](http://bl.ocks.org/mbostock/9764126) for an example.\n\n<a name=\"formatSpecifier\" href=\"#formatSpecifier\">#</a> d3.<b>formatSpecifier</b>(<i>specifier</i>) [<>](https://github.com/d3/d3-format/blob/master/src/formatSpecifier.js \"Source\")\n\nParses the specified *specifier*, returning an object with exposed fields that correspond to the [format specification mini-language](#locale_format) and a toString method that reconstructs the specifier. For example, `formatSpecifier(\"s\")` returns:\n\n```js\n{\n \"fill\": \" \",\n \"align\": \">\",\n \"sign\": \"-\",\n \"symbol\": \"\",\n \"zero\": false,\n \"width\": undefined,\n \"comma\": false,\n \"precision\": 6,\n \"type\": \"s\"\n}\n```\n\nThis method is useful for understanding how format specifiers are parsed and for deriving new specifiers. For example, you might compute an appropriate precision based on the numbers you want to format using [precisionFixed](#precisionFixed) and then create a new format:\n\n```js\nvar s = d3.formatSpecifier(\"f\");\ns.precision = precisionFixed(0.01);\nvar f = d3.format(s);\nf(42); // \"42.00\";\n```\n\n<a name=\"precisionFixed\" href=\"#precisionFixed\">#</a> d3.<b>precisionFixed</b>(<i>step</i>) [<>](https://github.com/d3/d3-format/blob/master/src/precisionFixed.js \"Source\")\n\nReturns a suggested decimal precision for fixed point notation given the specified numeric *step* value. The *step* represents the minimum absolute difference between values that will be formatted. (This assumes that the values to be formatted are also multiples of *step*.) For example, given the numbers 1, 1.5, and 2, the *step* should be 0.5 and the suggested precision is 1:\n\n```js\nvar p = d3.precisionFixed(0.5),\n f = d3.format(\".\" + p + \"f\");\nf(1); // \"1.0\"\nf(1.5); // \"1.5\"\nf(2); // \"2.0\"\n```\n\nWhereas for the numbers 1, 2 and 3, the *step* should be 1 and the suggested precision is 0:\n\n```js\nvar p = d3.precisionFixed(1),\n f = d3.format(\".\" + p + \"f\");\nf(1); // \"1\"\nf(2); // \"2\"\nf(3); // \"3\"\n```\n\nNote: for the `%` format type, subtract two:\n\n```js\nvar p = Math.max(0, d3.precisionFixed(0.05) - 2),\n f = d3.format(\".\" + p + \"%\");\nf(0.45); // \"45%\"\nf(0.50); // \"50%\"\nf(0.55); // \"55%\"\n```\n\n<a name=\"precisionPrefix\" href=\"#precisionPrefix\">#</a> d3.<b>precisionPrefix</b>(<i>step</i>, <i>value</i>) [<>](https://github.com/d3/d3-format/blob/master/src/precisionPrefix.js \"Source\")\n\nReturns a suggested decimal precision for use with [*locale*.formatPrefix](#locale_formatPrefix) given the specified numeric *step* and reference *value*. The *step* represents the minimum absolute difference between values that will be formatted, and *value* determines which SI prefix will be used. (This assumes that the values to be formatted are also multiples of *step*.) For example, given the numbers 1.1e6, 1.2e6, and 1.3e6, the *step* should be 1e5, the *value* could be 1.3e6, and the suggested precision is 1:\n\n```js\nvar p = d3.precisionPrefix(1e5, 1.3e6),\n f = d3.formatPrefix(\".\" + p, 1.3e6);\nf(1.1e6); // \"1.1M\"\nf(1.2e6); // \"1.2M\"\nf(1.3e6); // \"1.3M\"\n```\n\n<a name=\"precisionRound\" href=\"#precisionRound\">#</a> d3.<b>precisionRound</b>(<i>step</i>, <i>max</i>) [<>](https://github.com/d3/d3-format/blob/master/src/precisionRound.js \"Source\")\n\nReturns a suggested decimal precision for format types that round to significant digits given the specified numeric *step* and *max* values. The *step* represents the minimum absolute difference between values that will be formatted, and the *max* represents the largest absolute value that will be formatted. (This assumes that the values to be formatted are also multiples of *step*.) For example, given the numbers 0.99, 1.0, and 1.01, the *step* should be 0.01, the *max* should be 1.01, and the suggested precision is 3:\n\n```js\nvar p = d3.precisionRound(0.01, 1.01),\n f = d3.format(\".\" + p + \"r\");\nf(0.99); // \"0.990\"\nf(1.0); // \"1.00\"\nf(1.01); // \"1.01\"\n```\n\nWhereas for the numbers 0.9, 1.0, and 1.1, the *step* should be 0.1, the *max* should be 1.1, and the suggested precision is 2:\n\n```js\nvar p = d3.precisionRound(0.1, 1.1),\n f = d3.format(\".\" + p + \"r\");\nf(0.9); // \"0.90\"\nf(1.0); // \"1.0\"\nf(1.1); // \"1.1\"\n```\n\nNote: for the `e` format type, subtract one:\n\n```js\nvar p = Math.max(0, d3.precisionRound(0.01, 1.01) - 1),\n f = d3.format(\".\" + p + \"e\");\nf(0.01); // \"1.00e-2\"\nf(1.01); // \"1.01e+0\"\n```\n\n### Locales\n\n<a name=\"formatLocale\" href=\"#formatLocale\">#</a> d3.<b>formatLocale</b>(<i>definition</i>) [<>](https://github.com/d3/d3-format/blob/master/src/locale.js \"Source\")\n\nReturns a *locale* object for the specified *definition* with [*locale*.format](#locale_format) and [*locale*.formatPrefix](#locale_formatPrefix) methods. The *definition* must include the following properties:\n\n* `decimal` - the decimal point (e.g., `\".\"`).\n* `thousands` - the group separator (e.g., `\",\"`).\n* `grouping` - the array of group sizes (e.g., `[3]`), cycled as needed.\n* `currency` - the currency prefix and suffix (e.g., `[\"$\", \"\"]`).\n* `numerals` - optional; an array of ten strings to replace the numerals 0-9.\n* `percent` - optional; the percent suffix (defaults to `\"%\"`).\n\nNote that the *thousands* property is a misnomer, as the grouping definition allows groups other than thousands.\n\n<a name=\"formatDefaultLocale\" href=\"#formatDefaultLocale\">#</a> d3.<b>formatDefaultLocale</b>(<i>definition</i>) [<>](https://github.com/d3/d3-format/blob/master/src/defaultLocale.js \"Source\")\n\nEquivalent to [d3.formatLocale](#formatLocale), except it also redefines [d3.format](#format) and [d3.formatPrefix](#formatPrefix) to the new locale’s [*locale*.format](#locale_format) and [*locale*.formatPrefix](#locale_formatPrefix). If you do not set a default locale, it defaults to [U.S. English](https://github.com/d3/d3-format/blob/master/locale/en-US.json).\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/d3/d3-format.git"
},
"scripts": {
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../d3-format/build/d3-format.js d3-format.v1.js && cp ../d3-format/build/d3-format.min.js d3-format.v1.min.js && git add d3-format.v1.js d3-format.v1.min.js && git commit -m \"d3-format ${npm_package_version}\" && git push && cd - && zip -j build/d3-format.zip -- LICENSE README.md build/d3-format.js build/d3-format.min.js",
"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-format.js -c -m -o build/d3-format.min.js",
"pretest": "rm -rf build && mkdir build && rollup --banner \"$(preamble)\" -f umd -n d3 -o build/d3-format.js -- index.js",
"test": "tape 'test/**/*-test.js' && eslint index.js src"
},
"version": "1.2.0"
}
import formatLocale from "./locale";
var locale;
export var format;
export var formatPrefix;
defaultLocale({
decimal: ".",
thousands: ",",
grouping: [3],
currency: ["$", ""]
});
export default function defaultLocale(definition) {
locale = formatLocale(definition);
format = locale.format;
formatPrefix = locale.formatPrefix;
return locale;
}
import formatDecimal from "./formatDecimal";
export default function(x) {
return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
}
// Computes the decimal coefficient and exponent of the specified number x with
// significant digits p, where x is positive and p is in [1, 21] or undefined.
// For example, formatDecimal(1.23) returns ["123", 0].
export default function(x, p) {
if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
var i, coefficient = x.slice(0, i);
// The string returned by toExponential either has the form \d\.\d+e[-+]\d+
// (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
return [
coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
+x.slice(i + 1)
];
}
export default function(x, p) {
x = x.toPrecision(p);
out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
switch (x[i]) {
case ".": i0 = i1 = i; break;
case "0": if (i0 === 0) i0 = i; i1 = i; break;
case "e": break out;
default: if (i0 > 0) i0 = 0; break;
}
}
return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment