From 5ed1e562e4c8db04a282fd7257022e1dbd816a1f Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sat, 1 Jun 2019 14:05:03 -0400 Subject: [PATCH] fix strange memory debuging issue --- package-lock.json | 12 ++++++------ package.json | 2 ++ src/app/tools/emoji.tools.ts | 37 +++++++++++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2149fde8..46acb02d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "sengi", - "version": "0.9.0", + "version": "0.9.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -3892,6 +3892,11 @@ "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", "dev": true }, + "emojione": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/emojione/-/emojione-4.5.0.tgz", + "integrity": "sha512-Tq55Y3UgPOnayFDN+Qd6QMP0rpoH10a1nhSFN27s8gXW3qymgFIHiXys2ECYYAI134BafmI3qP9ni2rZOe9BjA==" + }, "emojis-list": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-2.1.0.tgz", @@ -6322,11 +6327,6 @@ "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=", "dev": true }, - "ionicons": { - "version": "4.5.5", - "resolved": "https://registry.npmjs.org/ionicons/-/ionicons-4.5.5.tgz", - "integrity": "sha512-dIGI73XG6Fg2Ps77ry5Ywe36Pq7wUGkDkl0pBhC4uhsiyoW+oXe+pplmarXEnKEcB5fmlkRrBOxYYzZaoRiUGw==" - }, "ip": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz", diff --git a/package.json b/package.json index cd723868..0f7e589b 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "scripts": { "ng": "ng", "start": "ng serve", + "start-mem": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng serve", "build": "ng build --prod", "test": "ng test", "test-nowatch": "ng test --watch=false", @@ -45,6 +46,7 @@ "bootstrap": "^4.1.3", "core-js": "^2.5.4", "ionicons": "^4.4.3", + "emojione": "~4.5.0", "rxjs": "^6.4.0", "tslib": "^1.9.0", "zone.js": "^0.8.29" diff --git a/src/app/tools/emoji.tools.ts b/src/app/tools/emoji.tools.ts index 614fd888..41071014 100644 --- a/src/app/tools/emoji.tools.ts +++ b/src/app/tools/emoji.tools.ts @@ -1,8 +1,9 @@ import { Emoji } from "../services/models/mastodon.interfaces"; -import { EmojiOne } from "./emoji-one"; +// import { EmojiOne } from "./emoji-one"; +import * as EmojiOne from 'emojione'; export class EmojiConverter { - private emojiOne = new EmojiOne(); + // private emojiOne = new EmojiOne(); applyEmojis(emojis: Emoji[], text: string, type: EmojiTypeEnum): string { if (!text) return text; @@ -14,12 +15,38 @@ export class EmojiConverter { if (emojis) { emojis.forEach(emoji => { - text = this.replaceAll(text, `:${emoji.shortcode}:`, `:${emoji.shortcode}:`) + try { + text = this.replaceAll(text, `:${emoji.shortcode}:`, `:${emoji.shortcode}:`); + } catch (err) {} }); } - text = this.emojiOne.toImage(text, className); + text = this.applyEmojiOne(className, text); + + // try { + // text = this.emojiOne.toImage(text, className); + // } catch (err) {} + return text; + } + + private applyEmojiOne(className: string, text: string): string{ + text = EmojiOne.toImage(text); + + while (text.includes('class="emojione"')) { + text = text.replace('class="emojione"', `class="emojione ${className}"`); + } + + while ( + text.includes("https://cdn.jsdelivr.net/emojione/assets/4.5/png/32/") + ) { + text = text.replace( + "https://cdn.jsdelivr.net/emojione/assets/4.5/png/32/", + "assets/emoji/72x72/" + ); + // text = text.replace('.png', '.svg'); + } + return text; }