Comparing version 1.1.8 to 1.2.0
@@ -6,3 +6,3 @@ /** | ||
module.exports = { | ||
separateAt: 13, // new line created after 'x' number of words. | ||
wordsPerLine: 13, // new line created after 'x' number of words. | ||
wordSeparater: " ", // words are separated by ' '. | ||
@@ -9,0 +9,0 @@ color: "\x1b[37m", // default text color [White] |
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!", { separatedAt: 7 }); | ||
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!", { wordsPerLine: 7 }); | ||
console.log(textwrapped); |
@@ -7,5 +7,5 @@ /* | ||
align: string | undefined, | ||
separateAt: number | undefined | ||
wordsPerLine: number | undefined | ||
} | ||
*/ |
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:"left", color:"magenta", separateAt: 20 }); | ||
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:"left", color:"magenta", wordsPerLine: 20 }); | ||
console.log(textwrapped); |
{ | ||
"name": "ruxe", | ||
"version": "1.1.8", | ||
"version": "1.2.0", | ||
"main": "src/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -28,5 +28,5 @@ <div align="center"> | ||
`align` - Alignment format of the paragraph :string:<br/> | ||
`separateAt` - Words after which a new line is created :number:<br/> | ||
`wordsPerLine` - Words after which a new line is created :number:<br/> | ||
<br/> | ||
By default `color` parameter is treated as `white`, the `align` parameter is treated as `left` and `separateAt` is treated as `13` | ||
By default `color` parameter is treated as `white`, the `align` parameter is treated as `left` and `wordsPerLine` is treated as `13` | ||
<br/><br/> | ||
@@ -42,3 +42,3 @@ **Available Colors:** black, red, green, yellow, blue, magenta, cyan and white | ||
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!", { color:"cyan", separateAt:8, align:"left" }); | ||
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!", { color:"cyan", wordsPerLine:8, align:"left" }); | ||
@@ -45,0 +45,0 @@ console.log(textwrapped); //each line of he paragraph will have 8 words, text color will be cyan in color and alignment of the paragraph will be left. |
@@ -5,3 +5,3 @@ /** | ||
* align: string, | ||
* separateAt: integer | ||
* wordsPerLine: integer | ||
* } | ||
@@ -14,2 +14,12 @@ */ | ||
/** | ||
* | ||
* @param {string} _str | ||
* @param {object} _config | ||
* @param {string} _config.color | ||
* @param {string} _config.align | ||
* @param {string} _config.wordsPerLine | ||
* @returns {string} | ||
*/ | ||
module.exports = function (_str, _config) { | ||
@@ -21,3 +31,3 @@ function typechecks() { | ||
if (typeof _config.align != "undefined" && typeof _config.align != "string") throw new TypeError("config.align must be a string."); | ||
if (typeof _config.separateAt != "undefined" && typeof _config.separateAt != "number") throw new TypeError("config.separateAt must be a string."); | ||
if (typeof _config.wordsPerLine != "undefined" && typeof _config.wordsPerLine != "number") throw new TypeError("config.wordsPerLine must be a string."); | ||
} | ||
@@ -28,10 +38,10 @@ | ||
var align = config.align; | ||
var separateAt = config.separateAt; | ||
var wordsPerLine = config.wordsPerLine; | ||
if(!_config) return [ color, align, separateAt ]; | ||
if(!_config) return [ color, align, wordsPerLine ]; | ||
if (_config.color && _config.color.toLowerCase() in colors) color = colors[_config.color.toLowerCase()]; | ||
if (_config.align && alignments.includes(_config.align.toLowerCase())) align = _config.align; | ||
if (_config.separateAt) separateAt = _config.separateAt; | ||
if (_config.wordsPerLine) wordsPerLine = _config.wordsPerLine; | ||
return [ color, align, separateAt ]; | ||
return [ color, align, wordsPerLine ]; | ||
} | ||
@@ -38,0 +48,0 @@ |
9352
135