├── .eslintrc.json
├── .github
├── dependabot.yml
└── workflows
│ ├── codeql-analysis.yml
│ ├── coverage-badge.yml
│ ├── docs.yml
│ └── main.yml
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── docs
├── .vitepress
│ └── config.ts
├── contributing
│ └── environment.md
├── guide
│ ├── basic-usage.md
│ ├── configuration.md
│ └── getting-started.md
├── hall-of-fame
│ └── contributors.md
└── index.md
├── examples
├── .gitignore
├── index.html
├── package-lock.json
├── package.json
├── src
│ ├── App.vue
│ ├── env.d.ts
│ └── main.ts
├── tsconfig.json
└── vite.config.ts
├── package-lock.json
├── package.json
├── src
├── converter
│ └── defaultConverter.ts
├── install.ts
└── timeago.ts
├── tests
└── unit
│ ├── defaultConverter.spec.ts
│ ├── install.spec.ts
│ └── timeago.spec.ts
├── tsconfig.json
└── vite.config.ts
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "parser": "vue-eslint-parser",
3 | "parserOptions": {
4 | "parser": "@typescript-eslint/parser",
5 | "ecmaVersion": "latest",
6 | "sourceType": "module"
7 | },
8 | "plugins": ["vue", "@typescript-eslint"],
9 | "extends": [
10 | "eslint:recommended",
11 | "plugin:vue/vue3-recommended",
12 | "plugin:@typescript-eslint/recommended"
13 | ],
14 | "globals": {
15 | "defineEmits": "readonly",
16 | "defineProps": "readonly",
17 | "withDefaults": "readonly"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "npm"
4 | directory: "/"
5 | schedule:
6 | interval: "daily"
7 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ "master" ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ "master" ]
20 | schedule:
21 | - cron: '24 11 * * 6'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 | permissions:
28 | actions: read
29 | contents: read
30 | security-events: write
31 |
32 | strategy:
33 | fail-fast: false
34 | matrix:
35 | language: [ 'javascript' ]
36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
38 |
39 | steps:
40 | - name: Checkout repository
41 | uses: actions/checkout@v3
42 |
43 | # Initializes the CodeQL tools for scanning.
44 | - name: Initialize CodeQL
45 | uses: github/codeql-action/init@v2
46 | with:
47 | languages: ${{ matrix.language }}
48 | # If you wish to specify custom queries, you can do so here or in a config file.
49 | # By default, queries listed here will override any specified in a config file.
50 | # Prefix the list here with "+" to use these queries and those in the config file.
51 |
52 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
53 | # queries: security-extended,security-and-quality
54 |
55 |
56 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57 | # If this step fails, then you should remove it and run the build manually (see below)
58 | - name: Autobuild
59 | uses: github/codeql-action/autobuild@v2
60 |
61 | # ℹ️ Command-line programs to run using the OS shell.
62 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
63 |
64 | # If the Autobuild fails above, remove it and uncomment the following three lines.
65 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
66 |
67 | # - run: |
68 | # echo "Run, Build Application using script"
69 | # ./location_of_script_within_repo/buildscript.sh
70 |
71 | - name: Perform CodeQL Analysis
72 | uses: github/codeql-action/analyze@v2
73 |
--------------------------------------------------------------------------------
/.github/workflows/coverage-badge.yml:
--------------------------------------------------------------------------------
1 | name: Generate CodeCoverage Badge
2 | on:
3 | push:
4 | branches: [ master ]
5 | jobs:
6 | checks:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@v4
10 | - name: Setup NodeJS
11 | uses: actions/setup-node@v4
12 | with:
13 | node-version: "22"
14 | cache: "npm"
15 | - name: Install dependencies
16 | run: npm install
17 | - name: Run unit tests with coverage
18 | run: |
19 | npm run coverage
20 | STATEMENTS=$(cat coverage/coverage-summary.json | jq -r '.total.statements.pct')
21 | echo "COVERAGE=$(echo ${STATEMENTS}%)" >> $GITHUB_ENV
22 | - name: Create Coverage Badge
23 | uses: schneegans/dynamic-badges-action@v1.7.0
24 | with:
25 | auth: ${{ secrets.GIST_SECRET }}
26 | gistID: 51a8c6c4f125bd6ec25a14a6f12e28bc
27 | filename: vue-timeago3_coverage.json
28 | label: Test Coverage
29 | message: ${{ env.COVERAGE }}
30 | namedLogo: vitest
31 | color: brightgreen
32 |
--------------------------------------------------------------------------------
/.github/workflows/docs.yml:
--------------------------------------------------------------------------------
1 | name: Generate and Deploy Docs
2 | on:
3 | release:
4 | types: [published]
5 | jobs:
6 | generate:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@v4
10 | - name: Setup NodeJS
11 | uses: actions/setup-node@v4
12 | with:
13 | node-version: "22"
14 | cache: "npm"
15 | - name: Install dependencies
16 | run: npm install
17 | - name: Generate static files
18 | run: npm run docs:build
19 | - name: Commit files
20 | run: |
21 | cd docs/.vitepress/dist
22 | git init
23 | git add -A
24 | git config --local user.email "action@github.com"
25 | git config --local user.name "GitHub Action"
26 | git commit -m 'deploy'
27 | - name: Push to GitHub pages
28 | uses: ad-m/github-push-action@v0.6.0
29 | with:
30 | github_token: ${{ secrets.GITHUB_TOKEN }}
31 | branch: docs
32 | force: true
33 | directory: ./docs/.vitepress/dist
34 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: Lint, Test, Build
2 | on:
3 | push:
4 | branches: [master]
5 | pull_request:
6 | branches: [master]
7 |
8 | jobs:
9 | lint:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v4
13 | - name: Setup Node
14 | uses: actions/setup-node@v4
15 | with:
16 | node-version: "22"
17 | cache: "npm"
18 | - name: Install dependencies
19 | run: npm install
20 | - name: Run ESLint
21 | run: npm run lint
22 | - name: Run Vue TSC
23 | run: npx vue-tsc --noEmit
24 | test:
25 | needs: lint
26 | runs-on: ubuntu-latest
27 | steps:
28 | - uses: actions/checkout@v4
29 | - name: Setup NodeJS
30 | uses: actions/setup-node@v4
31 | with:
32 | node-version: "22"
33 | cache: "npm"
34 | - name: Install dependencies
35 | run: npm install
36 | - name: Run Unit Tests
37 | run: npm run test
38 | build:
39 | needs: test
40 | runs-on: ubuntu-latest
41 | steps:
42 | - uses: actions/checkout@v4
43 | - name: Setup NodeJS
44 | uses: actions/setup-node@v4
45 | with:
46 | node-version: "22"
47 | cache: "npm"
48 | - name: Install dependencies
49 | run: npm install
50 | - name: Generate definitions
51 | run: npx vue-tsc --declaration --emitDeclarationOnly
52 | - name: Build Library
53 | run: npx vite build
54 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 | dist
4 | dist_types
5 | dist-ssr
6 | *.local
7 | /vue-timeago3-0.1.2.tgz
8 | coverage
9 | .npmrc
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # [2.3.0](https://github.com/MrDeerly/vue-timeago3/compare/v2.2.1...v2.3.0) (2022-06-11)
4 |
5 |
6 | ### Features
7 |
8 | * add type checking for strict converterOptions ([#262](https://github.com/MrDeerly/vue-timeago3/issues/262)) ([de6e9f7](https://github.com/MrDeerly/vue-timeago3/commit/de6e9f7808509584e6496cd90026070d6e711afa))
9 |
10 | # [2.2.0](https://github.com/MrDeerly/vue-timeago3/compare/v2.1.1...v2.2.0) (2022-04-30)
11 |
12 |
13 | ### Features
14 |
15 | * add strict option for defaultConverter ([#231](https://github.com/MrDeerly/vue-timeago3/issues/231)) ([6d8097a](https://github.com/MrDeerly/vue-timeago3/commit/6d8097ab5a0d8101f719e31930c22b9870cea3f7))
16 |
17 | ## [2.1.1](https://github.com/MrDeerly/vue-timeago3/compare/v2.1.0...v2.1.1) (2021-12-03)
18 |
19 |
20 |
21 | # [2.1.0](https://github.com/MrDeerly/vue-timeago3/compare/v2.1.0...v2.1.1) (2021-11-30)
22 |
23 |
24 | ### Features
25 |
26 | * add locale support ([01308ad](https://github.com/MrDeerly/vue-timeago3/commit/01308adab8313f3e5ddec4ea8e5e5c3c25d676fd))
27 |
28 |
29 |
30 | # [2.0.0](https://github.com/MrDeerly/vue-timeago3/compare/v2.1.0...v2.1.1) (2021-11-29)
31 |
32 |
33 | ### Bug Fixes
34 |
35 | * add vue shims ([06c21cc](https://github.com/MrDeerly/vue-timeago3/commit/06c21ccf7580d1f3e65c241f1ad78fc5fbc82c61))
36 |
37 |
38 | ### Reverts
39 |
40 | * Revert "initial release" ([bdebcc1](https://github.com/MrDeerly/vue-timeago3/commit/bdebcc17c9d7b8dcd92359235864db41405bfe09))
41 |
42 |
43 |
44 | ## [1.0.1](https://github.com/MrDeerly/vue-timeago3/compare/v2.1.0...v2.1.1) (2021-09-18)
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 MrDeerly
4 | Copyright (c) 2021 Sasha Koss and Lesha Koss https://kossnocorp.mit-license.org
5 | Copyright (c) EGOIST <0x142857@gmail.com> (github.com/egoist)
6 |
7 |
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy
10 | of this software and associated documentation files (the "Software"), to deal
11 | in the Software without restriction, including without limitation the rights
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | copies of the Software, and to permit persons to whom the Software is
14 | furnished to do so, subject to the following conditions:
15 |
16 | The above copyright notice and this permission notice shall be included in all
17 | copies or substantial portions of the Software.
18 |
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | SOFTWARE.
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ⏳ vue-timeago3
2 | [](https://npmjs.com/package/vue-timeago3) [](https://npmjs.com/package/vue-timeago3)  [](https://actions-badge.atrox.dev/0x0dr1y/vue-timeago3/goto?ref=master)   
3 |
4 | A time ago component for Vue.js 3 based on [vue-timeago for Vue 2 by egoist](https://github.com/egoist/vue-timeago).
5 |
6 | ## Table of Contents
7 |
8 | - [About](#sectionAbout)
9 | - [Usage](#sectionUsage)
10 | - [Installation](#sectionInstall)
11 | - [Register Plugin](#sectionRegister)
12 | - [Component](#sectionComponent)
13 |
14 |
15 |
16 | ## About
17 |
18 | **vue-timeago3** is a tiny component for Vue.js 3, to show the time passed since a specific date. You simply pass a date and get somewhat like `10 seconds ago`, `3 weeks ago`, `...` printed by the component
19 |
20 | ### Example
21 |
22 | | distance to now | result |
23 | | --------------- | ------------------------ |
24 | | 0 - 5 secs | less than 5 seconds ago |
25 | | 5 - 10 secs | less than 10 seconds ago |
26 | | 10 - 20 secs | less than 20 seconds ago |
27 | | 20 - 40 secs | half a minute ago |
28 | | 40 - 60 secs | less than a minute ago |
29 |
30 | See [date-fns/formatDistanceToNow](https://date-fns.org/v2.26.0/docs/formatDistanceToNow) for more details.
31 |
32 |
33 |
34 | ## Usage
35 |
36 | **Visit the [docs](https://0x0dr1y.github.io/vue-timeago3/) for more details!**
37 |
38 |
39 |
40 | ### Installation
41 |
42 | Currently the plugin is available via NPM and Yarn. To install it use one of the two package managers.
43 |
44 | ```javascript
45 | // NPM
46 | $ npm install vue-timeago3
47 |
48 | // Yarn
49 | $ yarn add vue-timeago3
50 | ```
51 |
52 |
53 |
54 | ### Register Plugin
55 |
56 | To register the plugin simply import and register it using the new global vue3 api. As an alternative the plugin could be imported in specific components only.
57 |
58 | ```javascript
59 | // src/main.ts
60 | import { createApp } from 'vue'
61 | import timeago from 'vue-timeago3'
62 |
63 | const app = createApp(App)
64 | ...
65 | app.use(timeago) // register timeago
66 | ...
67 | app.mount('#app')
68 | ```
69 |
70 | #### Plugin Options
71 |
72 | During the registration of the component you can specify a set of options, which will mutate the plugin **globally**. If you don't want to define global settings, skip this section and use props instead. To use options, simply pass them during the registration as an object:
73 |
74 | ```javascript
75 | // src/main.ts
76 | import { createApp } from 'vue'
77 | import timeago from 'vue-timeago3'
78 |
79 | const app = createApp(App)
80 | ...
81 | // define options
82 | const timeagoOptions = {
83 | converterOptions: {
84 | includeSeconds: false,
85 | }
86 | }
87 |
88 | app.use(timeago, timeagoOptions) // register timeago with options
89 | ...
90 | app.mount('#app')
91 | ```
92 |
93 | As of version 1.0.0 the following options are available:
94 |
95 | | option | type | description |
96 | |-----------------------------|----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
97 | | **name** | `string` | Register the component with a custom name. Default is: `timeago` |
98 | | **locale** | `Locale` (see [date-fns/Locale](https://date-fns.org/v2.26.0/docs/Locale)) | The `locale` specifies the language which is used to render the date. All available `date-fns` locales are supported by default. |
99 | | **converter** | `(date, defaultConvertOptions \| strictConverterOptions) => string` | A **converter** that formats regular dates in `x Seconds ago`, or in `xxx` style. Check out the [default converter](ahttps://github.com/0x0dr1y/vue-timeago3/blob/master/src/defaultConverter.js) which uses [date-fns formatDistanceToNow](https://date-fns.org/v2.24.0/docs/formatDistanceToNow) |
100 | | **defaultConverterOptions** | `Object` | Pass some extra settings to the default converter mentioned above. It supports the main options of `date-fns`, namingly:
`includeSeconds` - `boolean` - distances less than a minute are more detailed `addSuffix` - `boolean` - results specifies if now is earlier or later than the date passed `useStrict` - `false` - **if `true` you need to use the `strictConverterOptions` (see below)** |
101 | | **strictConverterOptions** | `Object` | Pass some extra settings to the default converter mentioned above. It supports the main options of `date-fns` strict converter, namingly:
`useStrict` - `true` - needs to be `true`, otherwise the `defaultConverterOptions` have to be used (see above) `addSuffix` - `boolean` - results specifies if now is earlier or later than the date passed `unit` - `second, minute, hour, day, month, year` if specified, will force a unit `roundingMethod` - `floor, ceil, round` which way to round partial units (default=round) |
102 |
103 |
104 |
105 | ### Component
106 |
107 | Once the plugin is registered you can straight up use it in your app.
108 |
109 | **Basic usage**:
110 |
111 | ```jsx
112 |
113 |
114 |
115 |
116 | This can be omitted by setting it to `0` or `false`.