UNPKG

@azizbecha/strkit

Version:

strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.

29 lines 1.16 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = isJWT; /** * Validates whether a given string is a valid JSON Web Token (JWT). * * @param token - The string to check if it's a valid JWT. * @returns A boolean indicating whether the string is a valid JWT. * * @example * isJWT("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiYWRtaW4iLCJpYXQiOjE1MTYyMzkwMjJ9.ZCXogGoSbb6dpzqSfrYtM4qvHmiim3g3b6pO5nQksjc"); // Output: true * isJWT("not-a-jwt-token"); // Output: false */ function isJWT(token) { // Regular expression to validate JWT structure const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$/; return jwtRegex.test(token); } }); //# sourceMappingURL=isJWT.js.map