diff --git a/History.md b/History.md index 3701092..dc4f1c4 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,7 @@ +## 0.6.0 + +Add client factory + ## 0.5.4 Excludes `coverage/` in .npmignore diff --git a/index.d.ts b/index.d.ts index 52ccff7..64ae27e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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(key: string, algorithm?: TAlgorithm, options?: IOptions): { + encode: (payload: T) => string, + decode: (token: string, noVerify: boolean) => T +}; diff --git a/lib/jwt.js b/lib/jwt.js index ab63f69..b950d71 100644 --- a/lib/jwt.js +++ b/lib/jwt.js @@ -43,7 +43,7 @@ var jwt = module.exports; /** * version */ -jwt.version = '0.5.5'; +jwt.version = '0.6.0'; /** * Decode jwt @@ -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 */ diff --git a/package.json b/package.json index 0431f08..d05fa77 100644 --- a/package.json +++ b/package.json @@ -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 ", "repository": { "type": "git", @@ -33,4 +33,4 @@ "main": "./index", "types": "./index.d.ts", "typings": "./index.d.ts" -} +} \ No newline at end of file