{"id":21701418,"url":"https://github.com/ktsn/truncator","last_synced_at":"2025-04-12T13:36:35.300Z","repository":{"id":57380313,"uuid":"49313772","full_name":"ktsn/truncator","owner":"ktsn","description":"Layout specific text truncator considering line length, content height or character length.","archived":false,"fork":false,"pushed_at":"2018-01-18T11:07:30.000Z","size":130,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T08:11:19.823Z","etag":null,"topics":["text","truncate","truncator","ui"],"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/ktsn.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":"2016-01-09T06:32:45.000Z","updated_at":"2021-08-21T03:29:22.000Z","dependencies_parsed_at":"2022-08-28T22:01:54.989Z","dependency_job_id":null,"html_url":"https://github.com/ktsn/truncator","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Ftruncator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Ftruncator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Ftruncator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Ftruncator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktsn","download_url":"https://codeload.github.com/ktsn/truncator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248487686,"owners_count":21112191,"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":["text","truncate","truncator","ui"],"created_at":"2024-11-25T20:19:50.726Z","updated_at":"2025-04-12T13:36:35.272Z","avatar_url":"https://github.com/ktsn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Truncator\n[![npm version](https://badge.fury.io/js/truncator.svg)](https://badge.fury.io/js/truncator)\n[![Build Status](https://travis-ci.org/ktsn/truncator.svg?branch=master)](https://travis-ci.org/ktsn/truncator)\n\nLayout specific text truncator considering line length, content height or character length.\n\n## Installation\nYou can install truncator from npm.\n\n```sh\n$ npm install truncator --save\n```\n\nIf you are using module loader such as [Rollup](http://rollupjs.org/) or [Webpack](https://webpack.github.io/):\n\n```js\nimport { truncate } from 'truncator';\n```\n\nAlso, you can use it from [unpkg](https://unpkg.com):\n\n```html\n\u003c!-- Normal build --\u003e\n\u003cscript src=\"https://unpkg.com/truncator\"\u003e\u003c/script\u003e\n\u003c!-- Minified build --\u003e\n\u003cscript src=\"https://unpkg.com/truncator/dist/truncator.min.js\"\u003e\u003c/script\u003e\n```\n\n```js\nvar truncate = Truncator.truncate;\n```\n\n## Usage\n\nJust call `truncate` function then the specified text will be truncated.\n\n```js\nvar truncator = truncate(el, text, options);\n```\n\n- `el`: `HTMLElement` that will be input `text`.\n- `text`: Truncate target `string`.\n- `options`: Truncate options `object`.\n  - `line`, `height` or `count`\n  - `ellipsis`: Ellipsis symbol. `null` indicates no symbol will be added. default: `'...'`\n\nThe returned object has the following methods:\n\n- `recalc()`: Retry to truncate the initially given `el` and `text` on the current state. It is useful if you want to adapt resizing the container element.\n- `restoreText()`: Restore the original text on `el`.\n\n```js\n// Re-truncate the text\ntruncator.recalc();\n\n// Restore the original text\ntruncator.restoreText();\n```\n\n### Example\n\n```js\nvar el = document.getElementById('wrapper');\nvar truncator = truncate(el, 'Target text', { line: 3, ellipsis: null });\n\nwindow.addEventListener('resize', function () {\n  truncator.recalc();\n});\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsn%2Ftruncator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktsn%2Ftruncator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsn%2Ftruncator/lists"}