Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dh-react-hooks/use-timeago

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dh-react-hooks/use-timeago

react hooks for timeago.js

  • 0.4.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

@dh-react-hooks/use-timeago

NPM version codecov

react hooks for timeago.js

Installation

npm i @dh-react-hooks/use-timeago

Arguments

propstyperequireddefaultdescription
dateTimeDate / number / stringtrueundefinedstart date
optionsobjectfalseundefinedoptions

  • Options
optionstypedefaultdescription
localestringen_USlocale
localeRegisterfunctionundefinedcustom local register function
intervalnumber1000update interval duration in milliseconds

Way to Ride

  • Common jS
const useTimeAgo = require('@dh-react-hooks/use-timeago')

  const timeago = useTimeAgo.default(
    Date.now(), 
    {
      interval: 30000
    }
  )
  • ESM
import useTimeAgo from '@dh-react-hooks/use-timeago'
  
  const timeago = useTimeAgo(
    Date.now(), 
    {
      interval: 30000
    }
  )
  • Custom Local
import useTimeAgo from '@dh-react-hooks/use-timeago'

  const localeRegister: function(number, index) {
    return [
      ['剛剛', '片刻後'],
      ['%s 秒前', '%s 秒後'],
      ['1 分鐘前', '1 分鐘後'],
      ['%s 分鐘前', '%s 分鐘後'],
      ['1 小時前', '1 小時後'],
      ['%s 小時前', '%s 小時後'],
      ['1 天前', '1 天後'],
      ['%s 天前', '%s 天後'],
      ['1 週前', '1 週後'],
      ['%s 週前', '%s 週後'],
      ['1 個月前', '1 個月後'],
      ['%s 個月前', '%s 個月後'],
      ['1 年前', '1 年後'],
      ['%s 年前', '%s 年後']
    ][index]
  }

  const timeago = useTimeAgo(
    Date.now(), 
    {
      locale: 'zh_TW',
      localeRegister
    }
  )

Reference

Keywords

FAQs

Package last updated on 18 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc