From 332f328617cf6a5cbe1f29e04eb6397ee95fbc1f Mon Sep 17 00:00:00 2001 From: David Ralph Date: Fri, 7 May 2021 14:39:39 +0100 Subject: [PATCH] 0.2.2 --- .npmignore | 9 ++++++++- README.md | 2 +- index.d.ts | 4 ++-- package.json | 6 +++--- src/index.ts | 32 ++++++++++++++++++++++---------- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/.npmignore b/.npmignore index 6d2eaaa..58d5e8e 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,8 @@ -.github/ \ No newline at end of file +# Folders +.github/ +.vscode/ +example/ +src/ + +# Files +tsconfig.json \ No newline at end of file diff --git a/README.md b/README.md index 17fb8a2..c8eef17 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # leeks.js -Simple ANSI styling for your terminal. +Simple ANSI styling for your terminal ## Features * Ultra lightweight (0 dependencies and small file size) diff --git a/index.d.ts b/index.d.ts index fc1304f..11fa90b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -92,7 +92,7 @@ declare module 'leeks.js' { * Change the colour of the given text using hexadecimals * @param {string} hex The hex to use * @param {string} t The text to show with the hexadecimal colour - * @credit [Stack Overflow](https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb) + * @credit [Stack Overflow](https://stackoverflow.com/q/5623838) */ export const hex: (hex: string, t: string) => string; @@ -100,7 +100,7 @@ declare module 'leeks.js' { * Change the background colour of the given text using hexadecimals * @param {string} hex The hex to use * @param {string} t The text to show with the hexadecimal colour - * @credit [Stack Overflow](https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb) + * @credit [Stack Overflow](https://stackoverflow.com/q/5623838) */ export const hexBg: (hex: string, t: string) => string; diff --git a/package.json b/package.json index 30c350c..7dbd747 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "leeks.js", - "version": "0.2.1", - "description": "Simple ANSI styling for your terminal.", + "version": "0.2.2", + "description": "Simple ANSI styling for your terminal", "author": "David \"ohlookitsderpy\" Ralph", "license": "MIT", "main": "dist/index.js", @@ -29,6 +29,6 @@ "256" ], "devDependencies": { - "@types/node": "^14.14.37" + "@types/node": "^15.0.2" } } diff --git a/src/index.ts b/src/index.ts index 386094b..2a8f3d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,28 +21,36 @@ let enabled = supports ? true : false; * @param {string} t The text to change the colour of */ let colours = []; -for (const c in Colours) colours[c] = (t: string) => enabled ? `\x1b[${Colours[c]}m${t}\x1b[0m` : t; +for (const c in Colours) { + colours[c] = (t: string) => enabled ? `\x1b[${Colours[c]}m${t}\x1b[0m` : t; +} /** * Change the style of the given text (List: https://docs.davidjcralph.co.uk/#/leeks) * @param {string} t The text to change the colour of */ let styles = []; -for (const s in Styles) styles[s] = (t: string) => `\x1b[${Styles[s]}m${t}\x1b[0m`; +for (const s in Styles) { + styles[s] = (t: string) => `\x1b[${Styles[s]}m${t}\x1b[0m`; +} /** * Change the colour of the given text using CSS keywords (List: https://docs.davidjcralph.co.uk/#/leeks) * @param {string} t The text to change the colour of */ let keywords = []; -for (const k in Keywords) keywords[k] = (t: string) => enabled ? rgb(Keywords[k], t) : t; +for (const k in Keywords) { + keywords[k] = (t: string) => enabled ? rgb(Keywords[k], t) : t; +} /** * Change the background colour of the given text using CSS keywords (List: https://docs.davidjcralph.co.uk/#/leeks) * @param {string} t The text to change the colour of */ let bgKeywords = []; -for (const k in Keywords) bgKeywords[k] = (t: string) => enabled ? rgbBg(Keywords[k], t) : t; +for (const k in Keywords) { + bgKeywords[k] = (t: string) => enabled ? rgbBg(Keywords[k], t) : t; +} /** * Change the colour of the given text using 8-bit colours @@ -92,7 +100,7 @@ export function rgbBg(rgb: [number, number, number], t: string) { * Change the colour of the given text using hexadecimals * @param {string} hex The hex to use * @param {string} t The text to show with the hexadecimal colour - * @credit [Stack Overflow](https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb) + * @credit [Stack Overflow](https://stackoverflow.com/q/5623838) */ export function hex(hex: string, t: string) { const bigint = parseInt(hex.replace('#', ''), 16); @@ -103,14 +111,13 @@ export function hex(hex: string, t: string) { * Change the background colour of the given text using hexadecimals * @param {string} hex The hex to use * @param {string} t The text to show with the hexadecimal colour - * @credit [Stack Overflow](https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb) + * @credit [Stack Overflow](https://stackoverflow.com/q/5623838) */ export function hexBg(hex: string, t: string) { const bigint = parseInt(hex.replace('#', ''), 16); return rgbBg([(bigint >> 16) & 255, (bigint >> 8) & 255, bigint & 255], t); }; - /** * Set an alias * @param {string} name The name of the alias @@ -120,9 +127,14 @@ export function hexBg(hex: string, t: string) { export function alias(name: string, type: string, value: string) { switch (type) { case 'colors': - case 'colours': colours[name] = value; break; - case 'styles': styles[name] = value; break; - default: throw new Error('Must be "colours", "colors" or "styles"'); + case 'colours': + colours[name] = value; + break; + case 'styles': + styles[name] = value; + break; + default: + throw new Error('Must be "colours", "colors" or "styles"'); } };