From 271e60e86731241447270f2b780e94581eac0e21 Mon Sep 17 00:00:00 2001 From: Matthew Stanciu Date: Sun, 16 Oct 2022 17:14:38 -0400 Subject: [PATCH] Add colors to `convertToLightning()` --- README.md | 7 ++++++- package.json | 2 +- src/time.ts | 3 ++- src/types/index.d.ts | 1 + test/LightningTime.test.ts | 13 +++++++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cff8aa9..b2b0084 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,12 @@ Assumes it's currently 12:07 AM returns { lightningString: '0~1~3|e' - strippedCharges: '0~1~3' + strippedCharges: '0~1~3', + colors: { + boltColor: '#01a100', + zapColor: '#3213d6', + sparkColor: '#f6853e' + } } */ ``` diff --git a/package.json b/package.json index cc0a8ef..d1b3969 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@purduehackers/time", - "version": "0.3.12", + "version": "0.4.0", "description": "convert between traditional time and lightning time ⚡️", "main": "dist/index.js", "module": "dist/esm/index.js", diff --git a/src/time.ts b/src/time.ts index f6a628e..d457464 100644 --- a/src/time.ts +++ b/src/time.ts @@ -71,7 +71,8 @@ export class LightningTime { charges.toString(16) return { lightningString, - strippedCharges: stripCharges(lightningString) + strippedCharges: stripCharges(lightningString), + colors: this.getColors(lightningString) } } diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 90f3d39..d614771 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -1,6 +1,7 @@ export interface LightningString { lightningString: string strippedCharges: string + colors: Colors } export interface LightningTimeObject { diff --git a/test/LightningTime.test.ts b/test/LightningTime.test.ts index db25562..2654d1f 100644 --- a/test/LightningTime.test.ts +++ b/test/LightningTime.test.ts @@ -19,6 +19,19 @@ describe('to lightning', () => { const convert = lightningTime.convertToLightning(time) expect(convert.strippedCharges).toEqual('8~0~0') }) + it('should convert to lightning and get colors', () => { + const time = new Date() + time.setHours(12) + time.setMinutes(0) + time.setSeconds(0) + const lightningTime = new LightningTime() + const convert = lightningTime.convertToLightning(time) + expect(convert.colors).toMatchObject({ + boltColor: '80a100', + zapColor: '3200d6', + sparkColor: 'f68500' + }) + }) }) describe('strip charges', () => {