Socket
Socket
Sign inDemoInstall

discord-emoji-canvas

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord-emoji-canvas - npm Package Compare versions

Comparing version 1.0.0 to 1.2.0

22

dist/function.js

@@ -7,3 +7,3 @@ "use strict";

if (!text)
throw new Error('(discord-emoji-canvas) No Text was provided');
throw new Error("(discord-emoji-canvas) No Text was provided");
if (!ctx)

@@ -18,23 +18,27 @@ throw new Error(`(discord-emoji-canvas) No Context was provided`);

let emojiPercent2 = 0.1;
let fontSize = parseInt(ctx.font);
let fontSize = ctx.font.replace(/[^\d.]/g, '');
let emojiSideMargin = fontSize * emojiPercent1;
let emojiUpMargin = fontSize * emojiPercent2;
let entity = text.split(" ");
const baseLine = ctx.measureText('').alphabeticBaseline;
const baseLine = ctx.measureText("").alphabeticBaseline;
let currWidth = 0;
for (let i = 0; i < entity.length; i++) { //starting loop
for (let i = 0; i < entity.length; i++) {
//starting loop
const ent = entity[i]; //getting current word or emoji
let parsed = twemoji_parser_1.parse(ent); //parsing to check later if emote is an twemoji
if (ent.match(/<?(a:|:)\w*:(\d{17}|\d{18})>/)) { //checking if custom emote or not
if (ent.match(/<?(a:|:)\w*:(\d{17}|\d{18})>/)) {
//checking if custom emote or not
let matched = ent.match(/<?(a:|:)\w*:(\d{17}|\d{18})>/);
let img = await canvas_1.loadImage(`https://cdn.discordapp.com/emojis/${matched[2]}.png`);
ctx.drawImage(img, x + currWidth + emojiSideMargin, y + emojiUpMargin - fontSize - baseLine, fontSize, fontSize);
currWidth += fontSize + (emojiSideMargin * 2) + fontSize / 5;
currWidth += fontSize + emojiSideMargin * 2 + fontSize / 5;
}
else if (parsed.length > 0) { //checking if twemoji or not
else if (parsed.length > 0) {
//checking if twemoji or not
let img = await canvas_1.loadImage(parsed[0].url);
ctx.drawImage(img, x + currWidth + emojiSideMargin, y + emojiUpMargin - fontSize - baseLine, fontSize, fontSize);
currWidth += fontSize + (emojiSideMargin * 2) + fontSize / 5;
currWidth += fontSize + emojiSideMargin * 2 + fontSize / 5;
}
else { //if string
else {
//if string
ctx.fillText(ent, x + currWidth, y);

@@ -41,0 +45,0 @@ currWidth += ctx.measureText(ent).width + fontSize / 5;

@@ -1,3 +0,3 @@

import fillWithEmoji from './function';
import Canvas from 'canvas';
import fillWithEmoji from "./function";
import Canvas from "canvas";
declare const _default: {

@@ -4,0 +4,0 @@ fillWithEmoji: (ctx: any, text: any, x: any, y: any) => Promise<void>;

{
"name": "discord-emoji-canvas",
"version": "1.0.0",
"version": "1.2.0",
"description": "A simple to use version of canvas specially meant for discord with custom emojis support!",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -1,35 +0,53 @@

import {loadImage} from 'canvas'
import {parse} from 'twemoji-parser'
const fillWithEmoji =async (ctx,text,x,y)=>{
if(!text)throw new Error('(discord-emoji-canvas) No Text was provided')
if(!ctx)throw new Error(`(discord-emoji-canvas) No Context was provided`)
if(!x)throw new Error(`(discord-emoji-canvas) No x axis was provided`)
if(!y)throw new Error(`(discord-emoji-canvas) No y axis was provided`)
// starting function from here
let emojiPercent1 = 0.1
let emojiPercent2 = 0.1
let fontSize =parseInt(ctx.font)
let emojiSideMargin = fontSize * emojiPercent1
let emojiUpMargin = fontSize * emojiPercent2
let entity = text.split(" ")
const baseLine = ctx.measureText('').alphabeticBaseline
let currWidth = 0
for(let i = 0;i<entity.length;i++){ //starting loop
const ent = entity[i] //getting current word or emoji
let parsed = parse(ent) //parsing to check later if emote is an twemoji
if(ent.match(/<?(a:|:)\w*:(\d{17}|\d{18})>/)){ //checking if custom emote or not
let matched = ent.match(/<?(a:|:)\w*:(\d{17}|\d{18})>/)
let img = await loadImage(`https://cdn.discordapp.com/emojis/${matched[2]}.png`)
ctx.drawImage(img,x + currWidth + emojiSideMargin,y + emojiUpMargin - fontSize -baseLine,fontSize,fontSize)
currWidth += fontSize + (emojiSideMargin * 2) + fontSize/5
}else if(parsed.length>0){ //checking if twemoji or not
let img = await loadImage(parsed[0].url)
ctx.drawImage(img,x + currWidth + emojiSideMargin,y + emojiUpMargin - fontSize -baseLine,fontSize,fontSize)
currWidth += fontSize + (emojiSideMargin * 2) + fontSize/5
}else { //if string
ctx.fillText(ent,x + currWidth,y)
currWidth += ctx.measureText(ent).width + fontSize/5
import { loadImage } from "canvas";
import { parse } from "twemoji-parser";
const fillWithEmoji = async (ctx, text, x, y) => {
if (!text) throw new Error("(discord-emoji-canvas) No Text was provided");
if (!ctx) throw new Error(`(discord-emoji-canvas) No Context was provided`);
if (!x) throw new Error(`(discord-emoji-canvas) No x axis was provided`);
if (!y) throw new Error(`(discord-emoji-canvas) No y axis was provided`);
// starting function from here
let emojiPercent1 = 0.1;
let emojiPercent2 = 0.1;
let fontSize = ctx.font.replace( /[^\d.]/g, '' )
let emojiSideMargin = fontSize * emojiPercent1;
let emojiUpMargin = fontSize * emojiPercent2;
let entity = text.split(" ");
const baseLine = ctx.measureText("").alphabeticBaseline;
let currWidth = 0;
for (let i = 0; i < entity.length; i++) {
//starting loop
const ent = entity[i]; //getting current word or emoji
let parsed = parse(ent); //parsing to check later if emote is an twemoji
if (ent.match(/<?(a:|:)\w*:(\d{17}|\d{18})>/)) {
//checking if custom emote or not
let matched = ent.match(/<?(a:|:)\w*:(\d{17}|\d{18})>/);
let img = await loadImage(
`https://cdn.discordapp.com/emojis/${matched[2]}.png`
);
ctx.drawImage(
img,
x + currWidth + emojiSideMargin,
y + emojiUpMargin - fontSize - baseLine,
fontSize,
fontSize
);
currWidth += fontSize + emojiSideMargin * 2 + fontSize / 5;
} else if (parsed.length > 0) {
//checking if twemoji or not
let img = await loadImage(parsed[0].url);
ctx.drawImage(
img,
x + currWidth + emojiSideMargin,
y + emojiUpMargin - fontSize - baseLine,
fontSize,
fontSize
);
currWidth += fontSize + emojiSideMargin * 2 + fontSize / 5;
} else {
//if string
ctx.fillText(ent, x + currWidth, y);
currWidth += ctx.measureText(ent).width + fontSize / 5;
}
}
}
export default fillWithEmoji
}
};
export default fillWithEmoji;

@@ -1,4 +0,4 @@

import fillWithEmoji from './function'
import Canvas from 'canvas'
export default {fillWithEmoji,Canvas}
export {fillWithEmoji,Canvas}
import fillWithEmoji from "./function";
import Canvas from "canvas";
export default { fillWithEmoji, Canvas };
export { fillWithEmoji, Canvas };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc