Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: adds jsdocs to timestamp helpers #619

Merged
merged 8 commits into from
Dec 24, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 45 additions & 10 deletions src/jwt/produce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,20 @@ export class ProduceJWT {
/**
* Set the "nbf" (Not Before) Claim.
*
* @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set. When number is passed
* that is used as a value, when string is passed it is resolved to a time span and added to the
* current timestamp.
* @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set.
*
* - If a `number` is passed as an argument, it's used as the `nbf` claim directly.
*
* - If a `Date` instance is passed, the value is converted to unix timestamp and used as `nbf` claim.
*
* - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp.
*
* Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day".
*
* Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m",
* "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y".
*
* If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability.
panva marked this conversation as resolved.
Show resolved Hide resolved
*/
setNotBefore(input: number | string | Date) {
if (typeof input === 'number') {
Expand All @@ -82,11 +93,22 @@ export class ProduceJWT {
}

/**
* Set the "exp" (Expiration Time) Claim.
*
* @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set. When number is
* passed that is used as a value, when string is passed it is resolved to a time span and added
* to the current timestamp.
* Set the `exp` (Expiration Time) Claim.
*
* @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set.
*
* - If a `number` is passed as an argument, it's used as the `exp` claim directly.
*
* - If a `Date` instance is passed, the value is converted to unix timestamp and used as `exp` claim.
*
* - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp.
*
* Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day".
*
* Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m",
* "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y".
*
* If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability.
panva marked this conversation as resolved.
Show resolved Hide resolved
*/
setExpirationTime(input: number | string | Date) {
if (typeof input === 'number') {
Expand All @@ -102,8 +124,21 @@ export class ProduceJWT {
/**
* Set the "iat" (Issued At) Claim.
*
* @param input "iat" (Issued At) Claim value to set on the JWT Claims Set. Default is current
* timestamp.
* @param input "iat" (Expiration Time) Claim value to set on the JWT Claims Set.
* - If no argument is used the current unix timestamp is used as the `iat` claim.
*
* - If a `number` is passed as an argument, it's used as the `iat` claim directly.
*
* - If a `Date` instance is passed, the value is converted to unix timestamp and used as `iat` claim.
*
* - If a `string` is passed it is resolved to a time span, and then added to the current unix timestamp.
*
* Format used for timespan should be a number followed by a unit, such as "5 minutes" or "1 day".
*
* Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins", "m",
* "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year", "years", "y".
*
* If the string is suffixed with "ago", or prefixed with a "-", the resulting timespan gets subtracted from the current unix timestamp. A "from now" suffix can also be used for readability.
panva marked this conversation as resolved.
Show resolved Hide resolved
*/
setIssuedAt(input?: number | string | Date) {
if (typeof input === 'undefined') {
Expand Down