diff --git a/test/test.type.ts b/test/test.type.ts index 753ee95..b6e31f5 100644 --- a/test/test.type.ts +++ b/test/test.type.ts @@ -5,4 +5,10 @@ tap.test('should state valuid utf8', async () => { expect(smartstring.type.isUtf8('hithere')).to.be.true; }); +tap.test('should state wether base64 string is valid', async () => { + const base64String = smartstring.base64.encode('hi there'); + expect(smartstring.type.isBase64(base64String)).to.be.true; + expect(smartstring.type.isBase64('hi there')).to.be.false; +}); + tap.start(); \ No newline at end of file diff --git a/ts/smartstring.type.ts b/ts/smartstring.type.ts index 35ad5ed..bbfef91 100644 --- a/ts/smartstring.type.ts +++ b/ts/smartstring.type.ts @@ -1,4 +1,5 @@ import * as plugins from './smartstring.plugins'; +import * as base64 from './smartstring.base64'; export const isUtf8 = (stringArg: string) => { const bytes = Buffer.from(stringArg); @@ -74,4 +75,8 @@ export const isUtf8 = (stringArg: string) => { } return true; -}; \ No newline at end of file +}; + +export const isBase64 = (stringArg: string) => { + return stringArg.endsWith('='); +};