{"id":20745633,"url":"https://github.com/keqingrong/tiny-save-as","last_synced_at":"2025-10-07T02:37:26.255Z","repository":{"id":65516589,"uuid":"151936295","full_name":"keqingrong/tiny-save-as","owner":"keqingrong","description":"A tiny JavaScript utility library for file saving","archived":false,"fork":false,"pushed_at":"2021-01-02T08:29:58.000Z","size":10,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T07:51:14.539Z","etag":null,"topics":["blob","download","file-saving","save-as"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/keqingrong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-07T11:53:11.000Z","updated_at":"2024-02-29T12:28:46.000Z","dependencies_parsed_at":"2023-01-26T22:25:12.785Z","dependency_job_id":null,"html_url":"https://github.com/keqingrong/tiny-save-as","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keqingrong%2Ftiny-save-as","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keqingrong%2Ftiny-save-as/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keqingrong%2Ftiny-save-as/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keqingrong%2Ftiny-save-as/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keqingrong","download_url":"https://codeload.github.com/keqingrong/tiny-save-as/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250580723,"owners_count":21453531,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blob","download","file-saving","save-as"],"created_at":"2024-11-17T07:21:32.482Z","updated_at":"2025-10-07T02:37:21.209Z","avatar_url":"https://github.com/keqingrong.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tiny-save-as\n\n[![npm version](https://img.shields.io/npm/v/tiny-save-as.svg)](https://www.npmjs.com/package/tiny-save-as)\n\n\u003e A tiny JavaScript utility library for file saving\n\nLive demo available at [here](https://keqingrong.github.io/tiny-save-as/example/).\n\n## Installation\n\n```sh\nnpm install tiny-save-as\n```\n\nThe CDN build is also available on unpkg:\n\n- [unpkg.com/tiny-save-as/dist/tiny-save-as.umd.js](https://unpkg.com/tiny-save-as/dist/tiny-save-as.umd.js)\n- [unpkg.com/tiny-save-as/dist/tiny-save-as.umd.min.js](https://unpkg.com/tiny-save-as/dist/tiny-save-as.umd.min.js)\n\n## Usage\n\n```js\n// Using ES modules\nimport savaAs from 'tiny-save-as';\n\n// Using ES modules with `import()`\nimport('https://unpkg.com/tiny-save-as/dist/tiny-save-as.esm.js')\n  .then(({default: saveAs}) =\u003e {\n    saveAs();\n  })\n  .catch((err) =\u003e {\n    console.log(err);\n  });\n\n// Using CommonJS modules\nconst savaAs = require('tiny-save-as');\n```\n\n## API\n\n```js\nsavaAs(blob, filename)\n```\n\n- **blob**: `Blob` A blob to save.\n- **filename**: `string` A file name with a suffix.\n\n## Examples\n\n### Text\n\n```js\nconst str = `# Lorem ipsum\nLorem ipsum dolor sit amet\nConsectetur adipiscing elit\n`;\nconst blob = new Blob([str], { type: 'text/markdown' });\nsaveAs(blob, 'README.md');\n```\n\n### JSON\n\n```js\nconst json = {\n  bool: true,\n  num: 3.14159,\n  str: '字符串',\n  obj: {\n    foo: 'bar'\n  }\n};\nconst str = JSON.stringify(json, null, 2) + '\\n';\nconst blob = new Blob([str], { type: 'application/json' });\nsaveAs(blob, 'blob.json');\n```\n\n### Canvas\n\n```js\nconst canvas = document.createElement('canvas');\ncanvas.width = 200;\ncanvas.height = 200;\nconst ctx = canvas.getContext('2d');\nctx.beginPath();\nctx.arc(100, 100, 50, 0, 2 * Math.PI);\nctx.fillStyle = '#f60';\nctx.fill();\n\n// save canvas as PNG image\ncanvas.toBlob((blob) =\u003e {\n  saveAs(blob, 'circle.png');\n});\n\n// or sava it as JPEG image\ncanvas.toBlob((blob) =\u003e {\n  saveAs(blob, 'circle.jpg');\n}, 'image/jpeg', 1);\n```\n\n### SVG\n\n```js\nconst str = `\u003c?xml version=\"1.0\"?\u003e\n\u003csvg xmlns=\"http://www.w3.org/2000/svg\"\u003e\n  \u003ccircle cx=\"50\" cy=\"50\" r=\"40\" stroke-width=\"1\" fill=\"#f60\" /\u003e\n\u003c/svg\u003e`;\n\nconst blob = new Blob([str], { type: 'image/svg+xml' });\nsaveAs(blob, 'circle.svg');\n```\n\n## Browsers support\n\n| [\u003cimg src=\"https://cdnjs.cloudflare.com/ajax/libs/browser-logos/69.0.4/edge/edge_48x48.png\" alt=\"IE / Edge\" width=\"24px\" height=\"24px\" /\u003e](https://godban.github.io/browsers-support-badges/)\u003c/br\u003eIE / Edge | [\u003cimg src=\"https://cdnjs.cloudflare.com/ajax/libs/browser-logos/69.0.4/firefox/firefox_48x48.png\" alt=\"Firefox\" width=\"24px\" height=\"24px\" /\u003e](https://godban.github.io/browsers-support-badges/)\u003c/br\u003eFirefox | [\u003cimg src=\"https://cdnjs.cloudflare.com/ajax/libs/browser-logos/69.0.4/chrome/chrome_48x48.png\" alt=\"Chrome\" width=\"24px\" height=\"24px\" /\u003e](https://godban.github.io/browsers-support-badges/)\u003c/br\u003eChrome | [\u003cimg src=\"https://cdnjs.cloudflare.com/ajax/libs/browser-logos/69.0.4/safari/safari_48x48.png\" alt=\"Safari\" width=\"24px\" height=\"24px\" /\u003e](https://godban.github.io/browsers-support-badges/)\u003c/br\u003eSafari |\n| --------- | --------- | --------- | --------- |\n| IE10, IE11, Edge| last 2 versions| last 2 versions| last 2 versions\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeqingrong%2Ftiny-save-as","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeqingrong%2Ftiny-save-as","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeqingrong%2Ftiny-save-as/lists"}