diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b8b3fe9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +readme.md +package-lock.json \ No newline at end of file diff --git a/examples/center_aligned.js b/examples/center_aligned.js new file mode 100644 index 0000000..38635af --- /dev/null +++ b/examples/center_aligned.js @@ -0,0 +1,5 @@ +const wrap = require("ruxe"); + +let textwrapped = wrap("Harry has a little farm, he has 4 cows, 15 chickens and 3 goats in his farm. He likes to grow a variety of crops such as wheat, barley, rice and corn! He loves farming! He also has good storage facilities in the farm and modern irrigation systems!", { align:"center" }); + +console.log(textwrapped); diff --git a/package.json b/package.json index 49d8f2f..4584057 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,33 @@ { "name": "ruxe", - "version": "1.2.0", + "version": "1.2.4", "main": "src/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "keywords": ["cli", "string", "text", "wrap", "paragraph", "manipulation","para", "stanza", "format", "color", "console", "formatting", "command-line-tool"], + "keywords": [ + "cli", + "string", + "text", + "wrap", + "paragraph", + "manipulation", + "para", + "stanza", + "format", + "color", + "console", + "formatting", + "command-line-tool" + ], "author": "jaipack17", "license": "MIT", "directories": { "example": "examples" }, "description": "format strings into paragraphs along with text styling.", - "repository": "https://github.com/jaipack17/ruxe" + "repository": "https://github.com/jaipack17/ruxe", + "dependencies": { + "center-align": "^1.0.1" + } } diff --git a/src/index.js b/src/index.js index 6391aaa..6d31e26 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,7 @@ const config = require("../config/default"); const alignments = require("../utils/alignments"); const colors = require("../utils/colors"); +var center = require('center-align'); /** * @@ -86,20 +87,14 @@ module.exports = function (_str, _config) { return fin; } - /* else if (p[1] == "center") { - for(var i = 0; i < a.length; i++){ - let spaces = Math.round((maxLen - a[i].length)/2); - if(spaces == 0) { - fin += " ".repeat(5) + a[i] + "\n" - } else { - fin += " ".repeat(spaces) + a[i] + "\n"; - } - } + let centered = center(a); + centered.forEach(line => { + fin += line + "\n"; + }) return fin; } - */ return s; } diff --git a/utils/alignments.js b/utils/alignments.js index b73841c..ba80ab2 100644 --- a/utils/alignments.js +++ b/utils/alignments.js @@ -1 +1 @@ -module.exports = ["right", "left"] +module.exports = ["right", "left", "center"]