[
  {
    "path": ".editorconfig",
    "content": "root = true\n\n[*]\nindent_style = tab\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\n\n[*.yml]\nindent_style = space\nindent_size = 2\n"
  },
  {
    "path": ".gitattributes",
    "content": "* text=auto eol=lf\n"
  },
  {
    "path": ".github/workflows/main.yml",
    "content": "name: CI\non:\n  - push\n  - pull_request\njobs:\n  test:\n    name: Node.js ${{ matrix.node-version }}\n    runs-on: ubuntu-latest\n    strategy:\n      fail-fast: false\n      matrix:\n        node-version:\n          - 16\n          - 14\n          - 12\n    steps:\n      - uses: actions/checkout@v5\n      - uses: actions/setup-node@v5\n        with:\n          node-version: ${{ matrix.node-version }}\n      - run: npm install\n      - run: npm test\n"
  },
  {
    "path": ".gitignore",
    "content": "node_modules\nyarn.lock\n"
  },
  {
    "path": ".npmrc",
    "content": "package-lock=false\n"
  },
  {
    "path": "index.d.ts",
    "content": "interface Options {\n\t/**\n\tMinimum value of the sparkline range.\n\n\tValues are scaled relative to this baseline. When not specified:\n\t- If `maximum` is set, defaults to `0` (for backwards compatibility)\n\t- Otherwise, defaults to the minimum value in the data\n\t*/\n\treadonly minimum?: number;\n\n\t/**\n\tMaximum value of the sparkline range.\n\n\tValues are scaled relative to this maximum. When not specified, defaults to the maximum value in the data.\n\t*/\n\treadonly maximum?: number;\n\n\t/**\n\tApply color styling to the sparklines.\n\n\tThe `'fire'` style uses a gradient from yellow to red. Each bar has a fixed width of one terminal column.\n\n\t@default 'fire'\n\t*/\n\treadonly style?: 'fire';\n}\n\n/**\nGenerate sparklines `▁▂▃▅▂▇`.\n\n@param numbers - The numbers to create the sparkline from.\n\n@example\n```\nimport sparkly from 'sparkly';\n\nsparkly([0, 3, 5, 8, 4, 3, 4, 10]);\n//=> '▁▃▄▇▄▃▄█'\n\n// Specifying anything other than finite numbers will cause holes\nsparkly([0, 3, 5, '', 4, 3, 4, 10]);\n//=> '▁▃▄ ▄▃▄█'\n\n// Specifying minimum and/or maximum options will change the sparkline range\nsparkly([1, 2, 3, 4, 5], {minimum: 0, maximum: 10});\n//=> '▁▂▃▄▄'\n\n// With only maximum set, minimum defaults to 0 for backwards compatibility\nsparkly([10, 20, 30, 40, 50], {maximum: 100});\n//=> '▁▂▃▄▄'\n\n// Specifying a style option will change the sparkline color\nsparkly([1, 2, 3, 4, 5, 6, 7, 8], {style: 'fire'});\n//=> Colored sparkline (gradient from yellow to red)\n```\n*/\nexport default function sparkly(\n\tnumbers: ReadonlyArray<number | ''>,\n\toptions?: Options\n): string;\n"
  },
  {
    "path": "index.js",
    "content": "import chalk from 'chalk';\n\nexport default function sparkly(numbers, options = {}) {\n\tif (!Array.isArray(numbers)) {\n\t\tthrow new TypeError('Expected an array');\n\t}\n\n\tlet ticks = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'];\n\tconst color = [[5, 5, 4], [5, 5, 3], [5, 5, 0], [5, 4, 0], [5, 3, 0], [5, 2, 0], [5, 1, 0], [5, 0, 0]];\n\tconst finiteNumbers = numbers.filter(number => Number.isFinite(number));\n\tconst minimum = typeof options.minimum === 'number' ? options.minimum : (typeof options.maximum === 'number' ? 0 : Math.min(...finiteNumbers));\n\tconst maximum = typeof options.maximum === 'number' ? options.maximum : Math.max(...finiteNumbers);\n\n\t// Use a high tick if data is constant and max is not equal to 0.\n\tif (minimum === maximum && maximum !== 0) {\n\t\tticks = [ticks[4]];\n\t}\n\n\treturn numbers.map(number => {\n\t\tif (!Number.isFinite(number)) {\n\t\t\treturn ' ';\n\t\t}\n\n\t\tlet tickIndex;\n\n\t\tif (minimum === maximum) {\n\t\t\ttickIndex = 0;\n\t\t} else {\n\t\t\ttickIndex = Math.ceil(((number - minimum) / (maximum - minimum)) * ticks.length) - 1;\n\t\t}\n\n\t\tif (tickIndex < 0) {\n\t\t\ttickIndex = 0;\n\t\t}\n\n\t\tif (options.style === 'fire') {\n\t\t\treturn chalk.rgb(...color[tickIndex])(ticks[tickIndex]);\n\t\t}\n\n\t\treturn ticks[tickIndex];\n\t}).join('');\n}\n"
  },
  {
    "path": "index.test-d.ts",
    "content": "import {expectType} from 'tsd';\nimport sparkly from './index.js';\n\nexpectType<string>(sparkly([0, 3, 5, 8, 4, 3, 4, 10]));\nexpectType<string>(sparkly([0, 3, 5, '', 4, 3, 4, 10]));\nexpectType<string>(sparkly([1, 2, 3, 4, 5], {minimum: 0}));\nexpectType<string>(sparkly([1, 2, 3, 4, 5], {maximum: 10}));\nexpectType<string>(sparkly([1, 2, 3, 4, 5, 6, 7, 8], {style: 'fire'}));\n"
  },
  {
    "path": "license",
    "content": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "package.json",
    "content": "{\n\t\"name\": \"sparkly\",\n\t\"version\": \"6.0.1\",\n\t\"description\": \"Generate sparklines `▁▂▃▅▂▇`\",\n\t\"license\": \"MIT\",\n\t\"repository\": \"sindresorhus/sparkly\",\n\t\"funding\": \"https://github.com/sponsors/sindresorhus\",\n\t\"author\": {\n\t\t\"name\": \"Sindre Sorhus\",\n\t\t\"email\": \"sindresorhus@gmail.com\",\n\t\t\"url\": \"https://sindresorhus.com\"\n\t},\n\t\"type\": \"module\",\n\t\"exports\": \"./index.js\",\n\t\"types\": \"./index.d.ts\",\n\t\"sideEffects\": false,\n\t\"engines\": {\n\t\t\"node\": \"^12.20.0 || ^14.13.1 || >=16.0.0\"\n\t},\n\t\"scripts\": {\n\t\t\"//test\": \"xo && ava && tsd\",\n\t\t\"test\": \"ava && tsd\"\n\t},\n\t\"files\": [\n\t\t\"index.js\",\n\t\t\"index.d.ts\"\n\t],\n\t\"keywords\": [\n\t\t\"spark\",\n\t\t\"sparkly\",\n\t\t\"line\",\n\t\t\"sparkline\",\n\t\t\"sparklines\",\n\t\t\"unicode\",\n\t\t\"data\",\n\t\t\"graph\",\n\t\t\"plot\",\n\t\t\"ascii\"\n\t],\n\t\"dependencies\": {\n\t\t\"chalk\": \"^4.1.2\"\n\t},\n\t\"devDependencies\": {\n\t\t\"ava\": \"^3.15.0\",\n\t\t\"tsd\": \"^0.19.0\",\n\t\t\"xo\": \"^0.46.4\"\n\t}\n}\n"
  },
  {
    "path": "readme.md",
    "content": "# ![sparkly](https://cloud.githubusercontent.com/assets/170270/4068189/1b47cab0-2e36-11e4-8b75-16b80330147e.gif)\n\n> Generate sparklines `▁▂▃▅▂▇`\n\nJavaScript port of [spark.sh](https://github.com/holman/spark).\n\n[Some cool use-cases.](https://github.com/holman/spark/wiki/Wicked-Cool-Usage)\n\n## Install\n\n```sh\nnpm install sparkly\n```\n\n## Usage\n\n```js\nimport sparkly from 'sparkly';\n\nsparkly([0, 3, 5, 8, 4, 3, 4, 10]);\n//=> '▁▃▄▇▄▃▄█'\n\n// Specifying anything other than finite numbers will cause holes\nsparkly([0, 3, 5, '', 4, 3, 4, 10]);\n//=> '▁▃▄ ▄▃▄█'\n\n// Specifying minimum and/or maximum options will change the sparkline range\nsparkly([1, 2, 3, 4, 5], {minimum: 0, maximum: 10});\n//=> '▁▂▃▄▄'\n\n// With only maximum set, minimum defaults to 0 for backwards compatibility\nsparkly([10, 20, 30, 40, 50], {maximum: 100});\n//=> '▁▂▃▄▄'\n\n// Specifying a style option will change the sparkline color\nsparkly([1, 2, 3, 4, 5, 6, 7, 8], {style: 'fire'});\n// ↓\n```\n\n<img src=\"screenshot.png\" width=\"383\">\n\n## API\n\n### sparkly(numbers, options?)\n\n#### numbers\n\nType: `number[]`\n\nThe numbers to create the sparkline from.\n\n#### options\n\nType: `object`\n\n##### minimum\n\nType: `number`\n\nMinimum value of the sparkline range.\n\nValues are scaled relative to this baseline. When not specified:\n- If `maximum` is set, defaults to `0` (for backwards compatibility)\n- Otherwise, defaults to the minimum value in the data\n\n##### maximum\n\nType: `number`\n\nMaximum value of the sparkline range.\n\nValues are scaled relative to this maximum. When not specified, defaults to the maximum value in the data.\n\n##### style\n\nType: `string`\\\nValues: `'fire'`\n\nApply color styling to the sparklines.\n\nThe `'fire'` style uses a gradient from yellow to red. Each bar has a fixed width of one terminal column.\n\n## Related\n\n- [sparkly-cli](https://github.com/sindresorhus/sparkly-cli) - CLI for this package\n"
  },
  {
    "path": "test.js",
    "content": "import test from 'ava';\nimport chalk from 'chalk';\nimport sparkly from './index.js';\n\nchalk.level = 3;\n\n// Example\nconsole.log('  ' + sparkly([1, 2, 3, 4, 5, 6, 7, 8], {style: 'fire'}) + '\\n');\n\ntest('creates graph', t => {\n\tt.is(sparkly([1, 5, 22, 13, 5]), '▁▂█▅▂');\n\tt.is(sparkly([0, 30, 55, 80, 33, 150]), '▁▂▃▅▂█');\n\tt.is(sparkly([5.5, 20]), '▁█');\n\tt.is(sparkly([1, 2, 3, 4, 100, 5, 10, 20, 50, 300]), '▁▁▁▁▃▁▁▁▂█');\n\tt.is(sparkly([1, 50, 100]), '▁▄█');\n\tt.is(sparkly([2, 4, 8]), '▁▃█');\n\tt.is(sparkly([1, 2, 3, 4, 5]), '▁▂▄▆█');\n\tt.is(sparkly([25, 45]), '▁█');\n});\n\ntest('anything other than finite numbers causes holes', t => {\n\tt.is(sparkly([1, '', 3, Number.NaN, 5]), '▁ ▄ █');\n});\n\ntest('use the middle tick if data is constant', t => {\n\tt.is(sparkly([10, 10, 10, 10, 10]), '▅▅▅▅▅');\n});\n\ntest('use the lowest tick if data is all 0', t => {\n\tt.is(sparkly([0, 0, 0, 0, 0]), '▁▁▁▁▁');\n});\n\ntest('minimum and maximum arguments set graph range', t => {\n\tt.is(sparkly([1], {minimum: 0, maximum: 1}), '█');\n\tt.is(sparkly([1, 2, 3, 4, 5], {minimum: 0, maximum: 10}), '▁▂▃▄▄');\n\tt.is(sparkly([10, 11, 12, 13], {minimum: 0}), '▇▇██');\n\tt.is(sparkly([10, 20, 30, 40, 50], {maximum: 100}), '▁▂▃▄▄');\n});\n\ntest('colored graph', t => {\n\tt.is(sparkly([1], {style: 'fire'}), chalk.rgb(5, 5, 4)('▅'));\n});\n"
  }
]