From 3efbf07f3310c0846afc038cddddefae72d98dde Mon Sep 17 00:00:00 2001 From: Egill Date: Sun, 12 Aug 2018 23:51:16 +0000 Subject: [PATCH] Switch from ES6 to ES5 to ensure compatability. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Runes** is not compiled with Babel, which leads to some difficulty when depending on it. It is currently [not possible](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify) to use `runes` in projects using `create-react-app`. The only ES6 features being used by **runes** are `const` and `let`. I therefore suggest that we switch to ES5, or add a compile step. --- index.js | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index 16a5f38..4cb598d 100644 --- a/index.js +++ b/index.js @@ -1,25 +1,25 @@ 'use strict' -const HIGH_SURROGATE_START = 0xd800 -const HIGH_SURROGATE_END = 0xdbff +var HIGH_SURROGATE_START = 0xd800 +var HIGH_SURROGATE_END = 0xdbff -const LOW_SURROGATE_START = 0xdc00 +var LOW_SURROGATE_START = 0xdc00 -const REGIONAL_INDICATOR_START = 0x1f1e6 -const REGIONAL_INDICATOR_END = 0x1f1ff +var REGIONAL_INDICATOR_START = 0x1f1e6 +var REGIONAL_INDICATOR_END = 0x1f1ff -const FITZPATRICK_MODIFIER_START = 0x1f3fb -const FITZPATRICK_MODIFIER_END = 0x1f3ff +var FITZPATRICK_MODIFIER_START = 0x1f3fb +var FITZPATRICK_MODIFIER_END = 0x1f3ff -const VARIATION_MODIFIER_START = 0xfe00 -const VARIATION_MODIFIER_END = 0xfe0f +var VARIATION_MODIFIER_START = 0xfe00 +var VARIATION_MODIFIER_END = 0xfe0f -const DIACRITICAL_MARKS_START = 0x20d0 -const DIACRITICAL_MARKS_END = 0x20ff +var DIACRITICAL_MARKS_START = 0x20d0 +var DIACRITICAL_MARKS_END = 0x20ff -const ZWJ = 0x200d +var ZWJ = 0x200d -const GRAPHEMS = [ +var GRAPHEMS = [ 0x0308, // ( ◌̈ ) COMBINING DIAERESIS 0x0937, // ( ष ) DEVANAGARI LETTER SSA 0x0937, // ( ष ) DEVANAGARI LETTER SSA @@ -41,9 +41,9 @@ function runes (string) { if (typeof string !== 'string') { throw new Error('string cannot be undefined or null') } - const result = [] - let i = 0 - let increment = 0 + var result = [] + var i = 0 + var increment = 0 while (i < string.length) { increment += nextUnits(i + increment, string) if (isGraphem(string[i + increment])) { @@ -73,15 +73,15 @@ function runes (string) { // Country flags: 4 code units (2 code points) // Variations: 2 code units function nextUnits (i, string) { - const current = string[i] + var current = string[i] // If we don't have a value that is part of a surrogate pair, or we're at // the end, only take the value at i if (!isFirstOfSurrogatePair(current) || i === string.length - 1) { return 1 } - const currentPair = current + string[i + 1] - let nextPair = string.substring(i + 2, i + 5) + var currentPair = current + string[i + 1] + var nextPair = string.substring(i + 2, i + 5) // Country flags are comprised of two regional indicator symbols, // each represented by a surrogate pair. @@ -133,8 +133,8 @@ function isZeroWidthJoiner (string) { } function codePointFromSurrogatePair (pair) { - const highOffset = pair.charCodeAt(0) - HIGH_SURROGATE_START - const lowOffset = pair.charCodeAt(1) - LOW_SURROGATE_START + var highOffset = pair.charCodeAt(0) - HIGH_SURROGATE_START + var lowOffset = pair.charCodeAt(1) - LOW_SURROGATE_START return (highOffset << 10) + lowOffset + 0x10000 } @@ -143,16 +143,16 @@ function betweenInclusive (value, lower, upper) { } function substring (string, start, width) { - const chars = runes(string) + var chars = runes(string) if (start === undefined) { return string } if (start >= chars.length) { return '' } - const rest = chars.length - start - const stringWidth = width === undefined ? rest : width - let endIndex = start + stringWidth + var rest = chars.length - start + var stringWidth = width === undefined ? rest : width + var endIndex = start + stringWidth if (endIndex > (start + rest)) { endIndex = undefined }