multichar-regex
Advanced tools
Comparing version 1.0.0 to 2.0.0
var multichar = require('./index') | ||
module.exports = function (string) { | ||
var matches = [] | ||
var matches = {} | ||
var match | ||
while (match = multichar.exec(string)) { | ||
matches.push({ | ||
value: match[0], | ||
index: match.index, | ||
length: match[0].length | ||
}) | ||
matches[match.index] = match[0] | ||
} | ||
return matches | ||
} |
{ | ||
"name": "multichar-regex", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "a regular expression that matches all the surrogate pairs and combining-marked characters in a string", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,4 +22,4 @@ # multichar-regex | ||
matches('oh hi, doggy 🐶 meet the sun: ☀️') | ||
=> [ { value: '🐶', index: 13, length: 2 }, | ||
{ value: '☀️', index: 30, length: 2 } ] | ||
// index: value | ||
=> { '13': '🐶', '30': '☀️' } | ||
``` | ||
@@ -26,0 +26,0 @@ |
@@ -25,7 +25,7 @@ var test = require('tape') | ||
var matches = match('oh hi doggy 🐶, are you from 🇨🇦?') | ||
assert.deepEqual(matches, [ | ||
{ value: '🐶', index: 12, length: 2 }, | ||
{ value: '🇨🇦', index: 29, length: 4 } | ||
], 'it does') | ||
assert.deepEqual(matches, { | ||
12: '🐶', | ||
29: '🇨🇦' | ||
}, 'it does') | ||
assert.end() | ||
}) |
3979
67