Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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])) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down