Skip to content

Commit

Permalink
fix: Funtion Name
Browse files Browse the repository at this point in the history
  • Loading branch information
devXprite committed Nov 20, 2023
1 parent 686de01 commit fce1a9c
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 30 deletions.
35 changes: 32 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,41 @@ const timesago = require('timesago');
```

## Usage
You can pass any ISO 8601 formatted dates and times to the timesago function.
You can pass any ISO 8601 formatted dates to the timesago function.

```javascript
const result = timesago('December 12, 2021');
const result1 = timesago('October 19, 2002');
console.log(result1); // 21 years ago

console.log(result); // 2 years ago
const result2 = timesago(1386786600000);
console.log(result2); // 9 years ago

const result3 = timesago(Date.now() - 3 * 24 * 60 * 60 * 1000);
console.log(result3); // 3 days ago

const result4 = timesago('2050-01-15T12:30:00Z');
console.log(result4); // in 26 years
```

## API

`timesago(timestamp, options)`

- `timestamp`: _(number, string, or Date object)_: The timestamp to convert to a time ago format. Accepted formats include:

- A number representing milliseconds since the Unix epoch.
- A string in ISO 8601 format (e.g., '2023-01-15T12:30:00Z').
- A JavaScript Date object.

- `options`: _(object, optional)_: An optional object with configuration options. Default options are:
```javascript
{
now: Date.now(), // current timestamp
prefixFromNow: 'in',
suffixAgo: 'ago',
justNow: 'just now',
blank: '',
}
```

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion dist/timesago.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/timesago.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export = timesAgo;
export = timesago;
/**
* Converts a timestamp to a human-readable "time ago" format.
*
Expand All @@ -15,7 +15,7 @@ export = timesAgo;
* console.log(result); // 2 years ago
*
*/
declare function timesAgo(time: string | number | Date, options?: {
declare function timesago(time: string | number | Date, options?: {
now?: string | number | Date;
prefixFromNow?: string;
suffixAgo?: string;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
},
"repository": {
"type": "git",
"url": "https://github.com/devXprite/timesAgo.git"
"url": "https://github.com/devXprite/timesago.git"
},
"homepage": "https://github.com/devXprite/timesAgo",
"homepage": "https://github.com/devXprite/timesago",
"engines": {
"node": ">=8.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

function timesAgo(time, options = {}) {
function timesago(time, options = {}) {
const defaultOptions = {
now: Date.now(),
prefixFromNow: 'in',
Expand Down Expand Up @@ -64,4 +64,4 @@ function timesAgo(time, options = {}) {
}
}

module.exports = timesAgo;
module.exports = timesago;
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script src="../dist/timesago.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/timesago@1"></script> -->
<script>
console.log(timesAgo('December 17, 2022'));
console.log(timesago('December 17, 2022'));
</script>
</body>

Expand Down

0 comments on commit fce1a9c

Please sign in to comment.