Skip to content

Commit

Permalink
add more endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowflake107 committed Oct 3, 2020
1 parent 5229ad8 commit 84f51d1
Show file tree
Hide file tree
Showing 15 changed files with 624 additions and 95 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
},
"homepage": "https://github.com/Snowflake107/Canvacord#readme",
"dependencies": {
"canvacord-assets": "^1.0.5",
"canvacord-assets": "^1.0.6",
"canvas": "^2.6.1",
"gifencoder": "^2.0.1",
"moment": "^2.27.0",
"moment-duration-format": "^2.3.2",
"node-canvas-with-twemoji-and-discord-emoji": "^1.1.4"
},
"devDependencies": {
"captcha-canvas": "^2.2.1",
"discord-canvas": "^1.3.2",
"jsdoc": "^3.6.6",
"jsdoc-skyceil": "^1.0.5"
Expand Down
26 changes: 26 additions & 0 deletions plugins/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,32 @@ class Util {
.replace(/\s/g, "");
}

/**
* Returns array of lines
* @param {object} params Params
* @param {string} text Text
* @param {CanvasRenderingContext2D} ctx CanvasRenderingContext2D
* @param {number} maxWidth Max width
*/
static getLines({ text, ctx, maxWidth }) {
if (!text) return [];
if (!ctx) throw new Error("Canvas context was not provided!");
if (!maxWidth) throw new Error("No max-width provided!");
const lines = [];

while (text.length) {
let i;
for (i = text.length; ctx.measureText(text.substr(0, i)).width > maxWidth; i -= 1);
const result = text.substr(0, i);
let j;
if (i !== text.length) for (j = 0; result.indexOf(" ", j) !== -1; j = result.indexOf(" ", j) + 1);
lines.push(result.substr(0, j || result.length));
text = text.substr(lines[lines.length - 1].length, text.length);
}

return lines;
}

}

module.exports = Util;
Loading

0 comments on commit 84f51d1

Please sign in to comment.