Skip to content

Commit

Permalink
0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcralph committed May 7, 2021
1 parent c075eda commit 332f328
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
9 changes: 8 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
.github/
# Folders
.github/
.vscode/
example/
src/

# Files
tsconfig.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# leeks.js <img src='https://leeks.js.org/assets/img/leeks-logo.png' height='64' width='64'>
Simple ANSI styling for your terminal.
Simple ANSI styling for your terminal

## Features
* Ultra lightweight (0 dependencies and small file size)
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ 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;

/**
* 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;

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -29,6 +29,6 @@
"256"
],
"devDependencies": {
"@types/node": "^14.14.37"
"@types/node": "^15.0.2"
}
}
32 changes: 22 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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"');
}
};

Expand Down

0 comments on commit 332f328

Please sign in to comment.