2.0.4 • Published 2 years ago

maxage v2.0.4

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
2 years ago

Maxage

Generate Max-Age header values or seconds via simple TimeString queries

Features

  • Generate Max-Age header values from simple TimeString queries
  • Get seconds as an integer from simple TimeString queries

Example TimeString: "2 weeks"

Installation

$ npm install maxage

Usage

Load with either import or require

// EcmaScript Modules
import { maxage, getSeconds } from 'maxage';

// CommonJS
const { maxage, getSeconds } = require('maxage');

There's also a single type that can be imported directly if needed

import type { TimeString } from 'maxage';

Then use the maxage or getSeconds functions. Simply:

/** getMaxAge */
const maxAge = maxage('1 day') // "Max-Age=86400"
/** getSeconds */
const secs = getSeconds('52 weeks') // 30844800

API Reference

maxage(age: TimeString) => string

The return value will be a string in following format: 'Max-Age=86400'

In case the age value passed is not a valid TimeString, the function will return the Max-Age with a value of 0.

getSeconds(timeString: TimeString) => number

In case the timeString value passed is not a valid TimeString, the function will return 0.

Typing

TimeString

Definition: ${number}${''|' '}${TimeUnit}

Where TimeUnit can be any of the following:

  • Minutes: 'm' | 'min' | 'mins' | 'minute' | 'minutes'
  • Hours: 'h' | 'hr' | 'hrs' | 'hour' | 'hours'
  • Days: 'd' | 'day' | 'days'
  • Weeks: 'w' | 'wk' | 'wks' | 'week' | 'weeks'

Notice the optional space between number and TimeUnit to suite your style. The following example are all valid TimeString values:

  • '1min'
  • '1 min'
  • '100wks'
  • '6 days'

Author

The author of Maxage is Abdul Jabbar

Open to contributions and issue reports.

License

MIT

1.2.0

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.1.2

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.4

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.1

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.11

3 years ago