Skip to content

Commit

Permalink
added prettier to nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikwilkowski committed May 27, 2022
1 parent 7478437 commit 3da7bdc
Show file tree
Hide file tree
Showing 62 changed files with 2,621 additions and 2,286 deletions.
4 changes: 4 additions & 0 deletions nodejs/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/
coverage/
fonts/
lib/
7 changes: 7 additions & 0 deletions nodejs/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
proseWrap: 'preserve',
singleQuote: true,
trailingComma: 'es5',
useTabs: true,
printWidth: 120,
}
5 changes: 4 additions & 1 deletion nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
"node": ">=10"
},
"scripts": {
"test": "yarn build && yarn test:unit && yarn test:lint && yarn test:types && yarn test:fonts",
"test": "yarn format && yarn build && yarn test:unit && yarn test:lint && yarn test:types && yarn test:fonts",
"test:fonts": "node ./test/fonttest.js",
"test:watch": "jest --watchAll --coverage",
"test:unit": "npx cross-env FORCE_COLOR=3 jest",
"test:types": "yarn types:clean && tsc -p tsconfig.json",
"test:lint": "eslint src/",
"test:format": "prettier --list-different \"**/*.{js,json}\"",
"format": "prettier --write \"**/*.{js,json}\"",
"build": "yarn build:lib && yarn build:bin && yarn build:fonts",
"build:bin": "npx mkdirp bin && mv lib/bin.js bin/index.js",
"build:lib": "npx mkdirp lib && babel src --out-dir lib",
Expand All @@ -48,6 +50,7 @@
"eslint": "^8.12.0",
"jest-cli": "^27.5.1",
"onchange": "^7.1.0",
"prettier": "^2.6.2",
"typescript": "^4.6.3"
},
"peerDependencies": {},
Expand Down
11 changes: 5 additions & 6 deletions nodejs/src/AddChar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
const { Debugging } = require('./Debugging.js');
const { Colorize } = require('./Colorize.js');


/**
* Add a new character to the output array
*
Expand All @@ -31,21 +30,21 @@ const { Colorize } = require('./Colorize.js');
*
* @return {array} - The output array with new line
*/
const AddChar = ( CHAR, output, fontLines, fontChars, fontColors, colors ) => {
Debugging.report( `Running AddChar with "${ CHAR }"`, 1 );
const AddChar = (CHAR, output, fontLines, fontChars, fontColors, colors) => {
Debugging.report(`Running AddChar with "${CHAR}"`, 1);

let lines = output.length - fontLines; // last line is fontLines tall and is located at the bottom of the output array

for( let i = lines; i < output.length; i++ ) { // iterate over last line
for (let i = lines; i < output.length; i++) {
// iterate over last line
let index = i - lines;

output[ i ] += Colorize( fontChars[ CHAR ][ index ], fontColors, colors );
output[i] += Colorize(fontChars[CHAR][index], fontColors, colors);
}

return output;
};


module.exports = exports = {
AddChar,
};
18 changes: 8 additions & 10 deletions nodejs/src/AddLetterSpacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
const { Debugging } = require('./Debugging.js');
const { Colorize } = require('./Colorize.js');



/**
* Add letter spacing for the next character
*
Expand All @@ -32,28 +30,28 @@ const { Colorize } = require('./Colorize.js');
*
* @return {array} - The output array with space
*/
const AddLetterSpacing = ( output, fontLines, fontLetterspace, fontColors, colors, letterSpacing ) => {
Debugging.report( `Running AddLetterSpacing`, 1 );
const AddLetterSpacing = (output, fontLines, fontLetterspace, fontColors, colors, letterSpacing) => {
Debugging.report(`Running AddLetterSpacing`, 1);

let lines = output.length - fontLines; // last line is fontLines tall and is located at the bottom of the output array

for( let i = lines; i < output.length; i++ ) { // iterate over last line
for (let i = lines; i < output.length; i++) {
// iterate over last line
let index = i - lines;
let space = Colorize( fontLetterspace[ index ], fontColors, colors );
let space = Colorize(fontLetterspace[index], fontColors, colors);

if( space.length === 0 && letterSpacing > 0 ) {
Debugging.report( `AddLetterSpacing: Adding space to letter spacing`, 1 );
if (space.length === 0 && letterSpacing > 0) {
Debugging.report(`AddLetterSpacing: Adding space to letter spacing`, 1);

space = ' ';
}

output[ i ] += space.repeat( letterSpacing );
output[i] += space.repeat(letterSpacing);
}

return output;
};


module.exports = exports = {
AddLetterSpacing,
};
19 changes: 8 additions & 11 deletions nodejs/src/AddLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

const { Debugging } = require('./Debugging.js');


/**
* Add a new line to the output array
*
Expand All @@ -28,31 +27,29 @@ const { Debugging } = require('./Debugging.js');
*
* @return {array} - The output array with new line
*/
const AddLine = ( output, fontLines, FontBuffer, lineHeight ) => {
Debugging.report( `Running AddLine`, 1 );
const AddLine = (output, fontLines, FontBuffer, lineHeight) => {
Debugging.report(`Running AddLine`, 1);

if( output.length === 0 ) {
if (output.length === 0) {
lineHeight = 0;
}

let lines = fontLines + output.length + lineHeight;
let length = output.length;

for( let i = length; i < lines; i++ ) {
for (let i = length; i < lines; i++) {
let index = i - length;

if( index > lineHeight ) {
output[ i ] = FontBuffer[ ( index - lineHeight ) ];
}
else {
output[ i ] = '';
if (index > lineHeight) {
output[i] = FontBuffer[index - lineHeight];
} else {
output[i] = '';
}
}

return output;
};


module.exports = exports = {
AddLine,
};
12 changes: 5 additions & 7 deletions nodejs/src/AddShortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,24 @@

'use strict';


/**
* Flatten the shortcuts in our cli options object
*
* @param {object} options - An object objects with a short key
*
* @return {object} - All short keys flattened into first level
*/
const AddShortcuts = ( options ) => {
const flatOptions = Object.assign( {}, options );
const AddShortcuts = (options) => {
const flatOptions = Object.assign({}, options);

Object.keys( flatOptions ).forEach( option => {
flatOptions[ option ]._name = option;
flatOptions[ flatOptions[ option ].short ] = flatOptions[ option ];
Object.keys(flatOptions).forEach((option) => {
flatOptions[option]._name = option;
flatOptions[flatOptions[option].short] = flatOptions[option];
});

return flatOptions;
};


module.exports = exports = {
AddShortcuts,
};
29 changes: 15 additions & 14 deletions nodejs/src/AlignText.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
const { Debugging } = require('./Debugging.js');
const { Size } = require('./Size.js');


/**
* Calculate the spaces to be added to the left of each line to align them either center or right
*
Expand All @@ -32,37 +31,39 @@ const { Size } = require('./Size.js');
*
* @return {array} - The output array with space added on the left for alignment
*/
const AlignText = ( output, lineLength, characterLines, align, size = Size ) => {
Debugging.report( `Running AlignText`, 1 );
const AlignText = (output, lineLength, characterLines, align, size = Size) => {
Debugging.report(`Running AlignText`, 1);

let space = 0;

if( align === 'center' ) { // calculate the size for center alignment
space = Math.ceil( ( size.width - lineLength ) / 2 );
if (align === 'center') {
// calculate the size for center alignment
space = Math.ceil((size.width - lineLength) / 2);

Debugging.report( `AlignText: Center lineLength: ${ lineLength }, size.width: ${ size.width }, space: ${ space }`, 2 );
Debugging.report(`AlignText: Center lineLength: ${lineLength}, size.width: ${size.width}, space: ${space}`, 2);
}

if( align === 'right' ) { // calculate the size for right alignment
if (align === 'right') {
// calculate the size for right alignment
space = size.width - lineLength;

Debugging.report( `AlignText: Right lineLength: ${ lineLength }, size.width: ${ size.width }, space: ${ space }`, 2 );
Debugging.report(`AlignText: Right lineLength: ${lineLength}, size.width: ${size.width}, space: ${space}`, 2);
}


if( space > 0 ) { // only add if there is something to add
if (space > 0) {
// only add if there is something to add
let lines = output.length - characterLines; // last line is characterLines tall and is located at the bottom of the output array
const spaces = ' '.repeat( space );
const spaces = ' '.repeat(space);

for( let i = lines; i < output.length; i++ ) { // iterate over last line (which can be several line breaks long)
output[ i ] = spaces + output[ i ];
for (let i = lines; i < output.length; i++) {
// iterate over last line (which can be several line breaks long)
output[i] = spaces + output[i];
}
}

return output;
};


module.exports = exports = {
AlignText,
};
16 changes: 7 additions & 9 deletions nodejs/src/CharLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

const { Debugging } = require('./Debugging.js');


/**
* Return the max width of a character by looking at its longest line
*
Expand All @@ -27,29 +26,28 @@ const { Debugging } = require('./Debugging.js');
*
* @return {number} - The length of a longest line in a character
*/
const CharLength = ( character, fontLines, letterSpacing ) => {
Debugging.report( `Running CharLength`, 1 );
const CharLength = (character, fontLines, letterSpacing) => {
Debugging.report(`Running CharLength`, 1);

let charWidth = 0;

for( let i = 0; i < fontLines; i++ ) {
let char = character[ i ].replace( /(<([^>]+)>)/ig, '' ); // get character and strip color infos
for (let i = 0; i < fontLines; i++) {
let char = character[i].replace(/(<([^>]+)>)/gi, ''); // get character and strip color infos

if( char.length > charWidth ) {
if (char.length > charWidth) {
charWidth = char.length; // assign only largest
}
}

if( charWidth === 0 && letterSpacing > 0 ) {
Debugging.report( `CharLength: Adding space to letter spacing`, 1 );
if (charWidth === 0 && letterSpacing > 0) {
Debugging.report(`CharLength: Adding space to letter spacing`, 1);

charWidth = 1;
}

return charWidth;
};


module.exports = exports = {
CharLength,
};
Loading

0 comments on commit 3da7bdc

Please sign in to comment.