Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.0

Add client factory

## 0.5.4

Excludes `coverage/` in .npmignore
Expand Down
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ export interface IOptions {
export function decode(token: string, key: string, noVerify?: boolean, algorithm?: TAlgorithm): any;

export function encode(payload: any, key: string, algorithm?: TAlgorithm, options?: IOptions): string;

export function client<T>(key: string, algorithm?: TAlgorithm, options?: IOptions): {
encode: (payload: T) => string,
decode: (token: string, noVerify: boolean) => T
};
22 changes: 21 additions & 1 deletion lib/jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var jwt = module.exports;
/**
* version
*/
jwt.version = '0.5.5';
jwt.version = '0.6.0';

/**
* Decode jwt
Expand Down Expand Up @@ -149,6 +149,26 @@ jwt.encode = function jwt_encode(payload, key, algorithm, options) {
return segments.join('.');
};

/**
* Generate jwt client
*
* @param {String} key
* @param {String} algorithm
* @param {Object} options
* @return {Object} client
* @api public
*/
jwt.client = function jwt_client(key, algorithm, options) {
return {
encode: function (payload) {
return jwt_encode(payload, key, algorithm, options);
},
decode: function (token, noVerify) {
return jwt_decode(token, key, noVerify, algorithm);
},
}
};

/**
* private util functions
*/
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jwt-simple",
"description": "JWT(JSON Web Token) encode and decode module",
"version": "0.5.5",
"version": "0.6.0",
"author": "Kazuhito Hokamura <k.hokamura@gmail.com>",
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,4 +33,4 @@
"main": "./index",
"types": "./index.d.ts",
"typings": "./index.d.ts"
}
}