From 1c4438dbb971caac28636fc84fcce0e6aec3df83 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Mon, 29 Jul 2019 18:38:55 -0400 Subject: [PATCH] emoji counting, fix #141 --- .../create-status/create-status.component.spec.ts | 7 +++++++ .../components/create-status/create-status.component.ts | 2 +- tsconfig.json | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/components/create-status/create-status.component.spec.ts b/src/app/components/create-status/create-status.component.spec.ts index 64716872..b73f4150 100644 --- a/src/app/components/create-status/create-status.component.spec.ts +++ b/src/app/components/create-status/create-status.component.spec.ts @@ -50,6 +50,13 @@ describe('CreateStatusComponent', () => { expect(component).toBeTruthy(); }); + it('should not count emoji as multiple chars', () => { + const status = '😃 😍 👌 👇 😱 😶 status with 😱 😶 emojis 😏 👍 '; + (component).maxCharLength = 500; + (component).countStatusChar(status); + expect((component).charCountLeft).toBe(461); + }); + it('should not parse small status', () => { const status = 'this is a cool status'; (component).maxCharLength = 500; diff --git a/src/app/components/create-status/create-status.component.ts b/src/app/components/create-status/create-status.component.ts index 348ee4da..574f0b3d 100644 --- a/src/app/components/create-status/create-status.component.ts +++ b/src/app/components/create-status/create-status.component.ts @@ -356,7 +356,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy { const currentStatus = parseStatus[parseStatus.length - 1]; const statusExtraChars = this.getMentionExtraChars(status); - const statusLength = currentStatus.length - statusExtraChars; + const statusLength = [...currentStatus].length - statusExtraChars; this.charCountLeft = this.maxCharLength - statusLength - this.getCwLength(); this.postCounts = parseStatus.length; } diff --git a/tsconfig.json b/tsconfig.json index 8cd9a30b..11da58ef 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,7 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es5", + "downlevelIteration": true, "typeRoots": [ "node_modules/@types" ],