'use strict';

const utils = require('./utils.js');

const parseEmojiSequencesWithId = ({ version, id }) => {
	const source = utils.readDataFile(version, id);
	if (!source) {
		return;
	}
	const propertyMap = new Map();
	const lines = source.split('\n');
	lines.forEach((line) => {
		if (!line || /^#/.test(line)) {
			return;
		}
		const data = line.trim().split('; ');
		const codePoints = data[0].trim().split(' ').map((hex) => {
			return parseInt(hex, 16);
		});
		const sequence = String.fromCodePoint(...codePoints);
		const property = data[1].split('#')[0].trim();
		if (propertyMap.has(property)) {
			propertyMap.get(property).add(sequence);
		} else {
			propertyMap.set(property, new Set([sequence]));
		}
	});
	const plainObject = {};
	for (const [property, codePoints] of propertyMap) {
		plainObject[property] = [...codePoints].sort((a, b) => a - b);
	}
	return plainObject;
};

const parseEmojiSequences = (version) => {
	return {
		...parseEmojiSequencesWithId({ version, id: 'emoji-sequences' }),
		...parseEmojiSequencesWithId({ version, id: 'emoji-zwj-sequences' }),
	};
};

module.exports = parseEmojiSequences;

@@ -373,25 +373,24 @@
 %09const c
-odePoints
+harRange
  = data%5B
@@ -396,76 +396,273 @@
 %5B0%5D.
-trim().split(' ').map((hex) =%3E %7B%0A%09%09%09return parseInt(hex
+replace('..', '-').trim();%0A%09%09const rangeParts = charRange.split('-');%0A%09%09const property = data%5B1%5D.split('#')%5B0%5D.trim();%0A%09%09if (rangeParts.length == 2) %7B%0A%09%09%09utils.range(%0A%09%09%09%09parseInt(rangeParts%5B0%5D, 16),%0A%09%09%09%09parseInt(rangeParts%5B1%5D
 , 16)
-;
 %0A%09%09
-%7D);%0A
+%09).forEach((codePoint) =%3E %7B%0A%09%09%09
 %09%09co
@@ -666,23 +666,21 @@
 %09const s
-equence
+ymbol
  = Strin
@@ -695,19 +695,16 @@
 dePoint(
-...
 codePoin
@@ -708,36 +708,207 @@
 oint
-s
 );%0A%09%09
-const property
+%09%09if (propertyMap.has(property)) %7B%0A%09%09%09%09%09propertyMap.get(property).add(symbol);%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09propertyMap.set(property, new Set(%5Bsymbol%5D));%0A%09%09%09%09%7D%0A%09%09%09%7D);%0A%09%09%7D else %7B%0A%09%09%09const codePoints
  = data%5B
 1%5D.s
@@ -907,33 +907,139 @@
 ata%5B
-1
+0
 %5D.
+trim().
 split('
-#')%5B0%5D.trim(
+ ').map((hex) =%3E %7B%0A%09%09%09%09return parseInt(hex, 16);%0A%09%09%09%7D);%0A%09%09%09const sequence = String.fromCodePoint(...codePoints
 );%0A
+%09
 %09%09if
@@ -1068,24 +1068,25 @@
 erty)) %7B%0A%09%09%09
+%09
 propertyMap.
@@ -1114,16 +1114,17 @@
 uence);%0A
+%09
 %09%09%7D else
@@ -1129,16 +1129,17 @@
 se %7B%0A%09%09%09
+%09
 property
@@ -1178,16 +1178,21 @@
 nce%5D));%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%7D);

Add missing Basic_Emoji data