{"id":19522167,"url":"https://github.com/captaincodeman/svelte-relative-time","last_synced_at":"2025-02-28T07:15:41.521Z","repository":{"id":65493862,"uuid":"593365145","full_name":"CaptainCodeman/svelte-relative-time","owner":"CaptainCodeman","description":"Relative Time for Svelte","archived":false,"fork":false,"pushed_at":"2024-08-28T21:33:28.000Z","size":213,"stargazers_count":42,"open_issues_count":3,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-14T05:08:29.595Z","etag":null,"topics":["date","dates","datetime","relative-time","svelte","sveltekit","time"],"latest_commit_sha":null,"homepage":"https://captaincodeman.github.io/svelte-relative-time/","language":"TypeScript","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/CaptainCodeman.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-25T20:41:58.000Z","updated_at":"2025-01-31T14:14:46.000Z","dependencies_parsed_at":"2024-04-29T20:53:40.808Z","dependency_job_id":"9903278d-1a8b-4042-9917-6bdd5020f9d9","html_url":"https://github.com/CaptainCodeman/svelte-relative-time","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/CaptainCodeman%2Fsvelte-relative-time","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCodeman%2Fsvelte-relative-time/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCodeman%2Fsvelte-relative-time/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCodeman%2Fsvelte-relative-time/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CaptainCodeman","download_url":"https://codeload.github.com/CaptainCodeman/svelte-relative-time/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239964542,"owners_count":19725952,"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":["date","dates","datetime","relative-time","svelte","sveltekit","time"],"created_at":"2024-11-11T00:37:29.586Z","updated_at":"2025-02-28T07:15:41.496Z","avatar_url":"https://github.com/CaptainCodeman.png","language":"TypeScript","readme":"# svelte-relative-time\n\nTiny Svelte action (620 byte) and Component to render relative times.\n\nBased partly on [Fast and Light Relative Time Strings in JS by Steve Sewell](https://www.builder.io/blog/relative-time) with output rounded to the nearest unit and live updates with a single interval timer.\n\n## Features\n\n- ✅ Action version is only 1006 bytes minified / 620 bytes gzipped\n- ✅ Component version enables SSR\n- ✅ Live updates by default (can be disabled)\n- ✅ Uses single interval timer for updating all components\n- ✅ Lightweight and GC friendly (single `Intl.RelativeTimeFormat` used per locale)\n- ✅ Instance updates scheduled for new visible change\n- ✅ Instance updates synchronized so all happen together\n\n## Usage\n\nInstall using your package manager of choice:\n\n    pnpm i svelte-relative-time\n\n### use:action Version\n\nThe `use:action` version only runs on the client so it suitable for Single Page Apps or when Server Side Rendering of timestamps isn't important.\n\n#### Import the action:\n\n```ts\nimport { relativeTime } from 'svelte-relative-time'\n```\n\n#### Apply to any HTML Element - the elements `.textContent` time will be set to the timestamp:\n\n```svelte\n\u003cspan use:relativeTime={options} /\u003e\n```\n\nOptions include:\n\n- `date` the Date or number to base the relative time on\n- `locale` the locale to use - defaults to browser default (`window.navigator.language`)\n- `live` whether to update live - defaults to true\n\n### Component Version\n\nThe Component version can be used for Server Side Rendering, but will require the locale to be set. See how to [synchronize locale between client and server when using SvelteKit](https://www.captaincodeman.com/internationalization-formatting-with-intl-ssr-sveltekit).\n\n#### Import the component:\n\n```ts\nimport RelativeTime from 'svelte-relative-time'\n\nconst date = Date.now()\nconst locale = 'en' // see note about on how to avoid hard coding this for SSR\n```\n\n#### Include Component with Properties:\n\n```svelte\n\u003cRelativeTime class=\"font-semibold\" {date} {locale} /\u003e\n```\n\n#### Custom Usage\n\nIf you need to apply additional styling based on the relative time, you can create your own component to use the additional `seconds`, `count`, and `units` properties in a callback (together with the formatted text) that can be used to determine any CSS or other DOM output required. Checkout the \"styled\" route for an example.\n\n## Performance\n\nThe package is designed to be as lightweight as possible. A single timer is used (which only runs when there are any instances requiring live updates), a single `Intl.RelativeTimeFormat` instance per locale is created and re-used, and instances are only re-evaluated when their displayed value will next change. So even with thousands of instances shouldn't cause performance issues.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptaincodeman%2Fsvelte-relative-time","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaptaincodeman%2Fsvelte-relative-time","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptaincodeman%2Fsvelte-relative-time/lists"}