Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ephox/polaris

Package Overview
Dependencies
Maintainers
2
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ephox/polaris - npm Package Compare versions

Comparing version 6.2.1 to 6.3.0-alpha.0

3

CHANGELOG.md

@@ -9,2 +9,5 @@ # Changelog

### Fixed
- `Search.findmany` now removes overlapped indices. #TINY-10062
## 6.2.0 - 2023-06-12

@@ -11,0 +14,0 @@

2

lib/main/ts/ephox/polaris/search/Sleuth.d.ts

@@ -5,3 +5,3 @@ import { PRange, PRegExp } from '../pattern/Types';

*
* Then sort the result by start point.
* Then sort by start point and remove overlapping result.
*/

@@ -8,0 +8,0 @@ declare const search: <T extends {

import { Arr } from '@ephox/katamari';
import * as Find from './Find';
const sort = (array) => {
const r = Array.prototype.slice.call(array, 0);
r.sort((a, b) => {
if (a.start < b.start) {
return -1;
}
else if (b.start < a.start) {
return 1;
}
else {
return 0;
}
});
return r;
const sort = (array) => Arr.sort(array, (a, b) => a.start - b.start);
// Array needs to be sorted first
const removeOverlapped = (array) => {
const sorted = sort(array);
return Arr.foldl(sorted, (acc, item) => {
const overlaps = Arr.exists(acc, (a) => item.start >= a.start && item.finish <= a.finish);
const matchingStartIndex = Arr.findIndex(acc, (a) => item.start === a.start);
// If there's no item with matching start in acc and within the start and finish, then we append, else we skip the item
// If there's a matching item with the same start in the acc, but it's not within finish, so we take the greater finish
// No need to get the ending part of the array as it's sorted, so we replace the item at the index with the greater finish item
return matchingStartIndex.fold(() => {
return overlaps ? acc : [...acc, item];
}, (index) => {
if (item.finish > acc[index].finish) {
const before = acc.slice(0, index);
return [...before, item];
}
return acc;
});
}, []);
};

@@ -21,3 +27,3 @@ /**

*
* Then sort the result by start point.
* Then sort by start point and remove overlapping result.
*/

@@ -34,5 +40,5 @@ const search = (text, targets) => {

});
return sort(unsorted);
return removeOverlapped(unsorted);
};
export { search };
//# sourceMappingURL=Sleuth.js.map

@@ -1,2 +0,2 @@

import { Assert, UnitTest } from '@ephox/bedrock-client';
import { Assert, it, describe } from '@ephox/bedrock-client';
import { Arr, Unicode } from '@ephox/katamari';

@@ -6,9 +6,9 @@ import * as Pattern from 'ephox/polaris/api/Pattern';

import * as Safe from 'ephox/polaris/pattern/Safe';
UnitTest.test('api.Search.findall (using api.Pattern)', () => {
describe('atomic.polaris.api.SearchFindTest', () => {
const checkAll = (expected, input, pattern) => {
const actual = Search.findall(input, pattern);
Assert.eq('', expected.length, actual.length);
Assert.eq(`Checking length of result for "${input}"`, expected.length, actual.length);
Arr.each(expected, (exp, i) => {
Assert.eq('', exp[0], actual[i].start);
Assert.eq('', exp[1], actual[i].finish);
Assert.eq(`Checking result of start for "${exp}"`, exp[0], actual[i].start);
Assert.eq(`Checking result of finish for "${exp}"`, exp[1], actual[i].finish);
});

@@ -22,46 +22,106 @@ };

const actual = Search.findmany(text, targets);
Assert.eq('', expected.length, actual.length);
Assert.eq(`Checking length of result for "${text}"`, expected.length, actual.length);
Arr.each(expected, (exp, i) => {
Assert.eq('', exp[0], actual[i].start);
Assert.eq('', exp[1], actual[i].finish);
Assert.eq('', exp[2], actual[i].name);
Assert.eq(`Checking result of start for "${exp}"`, exp[0], actual[i].start);
Assert.eq(`Checking result of finish for "${exp}"`, exp[1], actual[i].finish);
Assert.eq(`Checking result of name for "${exp}"`, exp[2], actual[i].name);
});
};
checkAll([], 'eskimo', Pattern.unsafetoken('hi'));
checkAll([[1, 7]], ' cattle', Pattern.unsafetoken('cattle'));
checkAll([], 'acattle', Pattern.unsafeword('cattle'));
checkAll([[1, 7]], ' cattle', Pattern.unsafeword('cattle'));
checkAll([], Unicode.zeroWidth + 'dog ', Pattern.safeword('dog'));
checkAll([[3, 7], [10, 14]], `no it's i it's done.`, Pattern.unsafetoken(`it's`));
checkAll([[0, 12]], `catastrophe'`, Pattern.unsafetoken(`catastrophe'`));
checkAll([[0, 3]], 'sre', Pattern.unsafeword('sre'));
checkAll([[0, 3]], 'sre ', Pattern.unsafeword('sre'));
checkAll([[1, 4]], ' sre', Pattern.unsafeword('sre'));
checkAll([[1, 4]], ' sre ', Pattern.unsafeword('sre'));
checkAll([[0, 3], [4, 7]], 'sre sre', Pattern.unsafeword('sre'));
checkAll([[1, 4], [5, 8]], ' sre sre', Pattern.unsafeword('sre'));
checkAll([[1, 4], [5, 8], [9, 12]], ' sre sre sre', Pattern.unsafeword('sre'));
checkAll([[0, 3], [4, 7], [8, 11]], 'sre sre sre ', Pattern.unsafeword('sre'));
checkAll([[1, 4], [5, 8], [9, 12]], ' sre sre sre ', Pattern.unsafeword('sre'));
checkAll([['this '.length, 'this e'.length + Unicode.zeroWidth.length + 'nds'.length]], 'this e' + Unicode.zeroWidth + 'nds here', Pattern.unsafeword('e' + Unicode.zeroWidth + 'nds'));
const prefix = Safe.sanitise('[');
const suffix = Safe.sanitise(']');
checkAll([[1, 5]], ' [wo] and more', Pattern.unsafetoken(prefix + '[^' + suffix + ']*' + suffix));
checkMany([], '', []);
checkMany([
[1, 3, 'alpha']
], ' aa bb cc', [
testData(Pattern.safeword('aa'), 'alpha')
]);
checkMany([
[0, 2, 'alpha'],
[3, 6, 'beta'],
[8, 18, 'gamma']
], 'aa bbb abcdefghij', [
testData(Pattern.safeword('bbb'), 'beta'),
testData(Pattern.safeword('abcdefghij'), 'gamma'),
testData(Pattern.safeword('aa'), 'alpha'),
testData(Pattern.safeword('not-there'), 'delta')
]);
it('TINY-10062: checkAll ', () => {
checkAll([], 'eskimo', Pattern.unsafetoken('hi'));
checkAll([[1, 7]], ' cattle', Pattern.unsafetoken('cattle'));
checkAll([], 'acattle', Pattern.unsafeword('cattle'));
checkAll([[1, 7]], ' cattle', Pattern.unsafeword('cattle'));
checkAll([], Unicode.zeroWidth + 'dog ', Pattern.safeword('dog'));
checkAll([[3, 7], [10, 14]], `no it's i it's done.`, Pattern.unsafetoken(`it's`));
checkAll([[0, 12]], `catastrophe'`, Pattern.unsafetoken(`catastrophe'`));
checkAll([[0, 3]], 'sre', Pattern.unsafeword('sre'));
checkAll([[0, 3]], 'sre ', Pattern.unsafeword('sre'));
checkAll([[1, 4]], ' sre', Pattern.unsafeword('sre'));
checkAll([[1, 4]], ' sre ', Pattern.unsafeword('sre'));
checkAll([[0, 3], [4, 7]], 'sre sre', Pattern.unsafeword('sre'));
checkAll([[1, 4], [5, 8]], ' sre sre', Pattern.unsafeword('sre'));
checkAll([[1, 4], [5, 8], [9, 12]], ' sre sre sre', Pattern.unsafeword('sre'));
checkAll([[0, 3], [4, 7], [8, 11]], 'sre sre sre ', Pattern.unsafeword('sre'));
checkAll([[1, 4], [5, 8], [9, 12]], ' sre sre sre ', Pattern.unsafeword('sre'));
checkAll([['this '.length, 'this e'.length + Unicode.zeroWidth.length + 'nds'.length]], 'this e' + Unicode.zeroWidth + 'nds here', Pattern.unsafeword('e' + Unicode.zeroWidth + 'nds'));
checkAll([[1, 5]], ' [wo] and more', Pattern.unsafetoken(Safe.sanitise('[') + '[^' + Safe.sanitise(']') + ']*' + Safe.sanitise(']')));
});
it('TINY-10062: checkMany ', () => {
checkMany([], '', []);
checkMany([
[1, 3, 'alpha']
], ' aa bb cc', [
testData(Pattern.safeword('aa'), 'alpha')
]);
checkMany([
[0, 3, 'alpha'],
[4, 9, 'beta'],
[10, 16, 'gamma'],
[17, 19, 'delta'],
], '<p> Hello World</p>', [
testData(Pattern.safeword('<p>'), 'alpha'),
testData(Pattern.safeword('Hello'), 'beta'),
testData(Pattern.safeword('World<'), 'gamma'),
testData(Pattern.safeword('p>'), 'delta'),
]);
checkMany([
[0, 8, 'alpha'],
[9, 15, 'beta'],
[16, 18, 'gamma'],
], '<p>Hello World</p>', [
testData(Pattern.safeword('<p>Hello'), 'alpha'),
testData(Pattern.safeword('World<'), 'beta'),
testData(Pattern.safeword('p>'), 'gamma'),
]);
checkMany([
[0, 3, 'alpha'],
[4, 9, 'beta'],
[10, 15, 'gamma'],
[16, 17, 'epsilon'],
[18, 20, 'zeta'],
], '<p> Hello World </p>', [
testData(Pattern.safeword('<p>'), 'alpha'),
testData(Pattern.safeword('Hello'), 'beta'),
testData(Pattern.safeword('World'), 'gamma'),
testData(Pattern.safeword('<'), 'epsilon'),
testData(Pattern.safeword('p>'), 'zeta'),
]);
checkMany([
[0, 8, 'alpha'],
[9, 14, 'beta'],
[15, 16, 'delta'],
[17, 19, 'gamma'],
], '<p>Hello World </p>', [
testData(Pattern.safeword('<p>Hello'), 'alpha'),
testData(Pattern.safeword('World'), 'beta'),
testData(Pattern.safeword('<'), 'delta'),
testData(Pattern.safeword('p>'), 'gamma'),
]);
checkMany([
[7, 16, 'alpha'],
[25, 27, 'beta'],
], 'Test. [IF:INTEXT]Test2 [/IF]', [
testData(Pattern.safeword('IF:INTEXT'), 'alpha'),
testData(Pattern.safeword('IF'), 'beta'),
]);
checkMany([
[8, 10, 'alpha'],
[18, 27, 'beta'],
], 'Test. [/IF]Test2 [IF:INTEXT]', [
testData(Pattern.safeword('IF'), 'alpha'),
testData(Pattern.safeword('IF:INTEXT'), 'beta'),
]);
checkMany([
[0, 2, 'alpha'],
[3, 6, 'beta'],
[8, 18, 'gamma']
], 'aa bbb abcdefghij', [
testData(Pattern.safeword('bbb'), 'beta'),
testData(Pattern.safeword('abcdefghij'), 'gamma'),
testData(Pattern.safeword('aa'), 'alpha'),
testData(Pattern.safeword('not-there'), 'delta')
]);
});
});
//# sourceMappingURL=SearchFindTest.js.map
{
"name": "@ephox/polaris",
"description": "This project does data manipulation on arrays and strings.",
"version": "6.2.1",
"version": "6.3.0-alpha.0",
"repository": {

@@ -38,3 +38,3 @@ "type": "git",

"types": "./lib/main/ts/ephox/polaris/api/Main.d.ts",
"gitHead": "5e3bea2581ef30fdca6e9d9c6daba5765ca2d4ff"
"gitHead": "6752c25afcbb37e66c7281202327cdd1248b671d"
}

@@ -6,14 +6,26 @@ import { Arr } from '@ephox/katamari';

const sort = <T extends PRange>(array: T[]): T[] => {
const r: T[] = Array.prototype.slice.call(array, 0);
r.sort((a, b) => {
if (a.start < b.start) {
return -1;
} else if (b.start < a.start) {
return 1;
} else {
return 0;
}
});
return r;
const sort = <T extends PRange>(array: T[]): T[] => Arr.sort(array, (a, b) => a.start - b.start);
// Array needs to be sorted first
const removeOverlapped = <T extends PRange>(array: T[]): T[] => {
const sorted = sort(array);
return Arr.foldl(sorted, (acc, item) => {
const overlaps = Arr.exists(acc, (a) => item.start >= a.start && item.finish <= a.finish);
const matchingStartIndex = Arr.findIndex(acc, (a) => item.start === a.start);
// If there's no item with matching start in acc and within the start and finish, then we append, else we skip the item
// If there's a matching item with the same start in the acc, but it's not within finish, so we take the greater finish
// No need to get the ending part of the array as it's sorted, so we replace the item at the index with the greater finish item
return matchingStartIndex.fold(() => {
return overlaps ? acc : [ ...acc, item ];
},
(index) => {
if (item.finish > acc[index].finish) {
const before = acc.slice(0, index);
return [ ...before, item ];
}
return acc;
});
}, [] as T[]);
};

@@ -24,3 +36,3 @@

*
* Then sort the result by start point.
* Then sort by start point and remove overlapping result.
*/

@@ -37,4 +49,3 @@ const search = <T extends { pattern: PRegExp }>(text: string, targets: T[]): Array<T & PRange> => {

});
return sort(unsorted);
return removeOverlapped(unsorted);
};

@@ -41,0 +52,0 @@

@@ -1,2 +0,2 @@

import { Assert, UnitTest } from '@ephox/bedrock-client';
import { Assert, it, describe } from '@ephox/bedrock-client';
import { Arr, Unicode } from '@ephox/katamari';

@@ -9,11 +9,12 @@

UnitTest.test('api.Search.findall (using api.Pattern)', () => {
describe('atomic.polaris.api.SearchFindTest', () => {
const checkAll = (expected: [number, number][], input: string, pattern: PRegExp) => {
const actual = Search.findall(input, pattern);
Assert.eq('', expected.length, actual.length);
Assert.eq(`Checking length of result for "${input}"`, expected.length, actual.length);
Arr.each(expected, (exp, i) => {
Assert.eq('', exp[0], actual[i].start);
Assert.eq('', exp[1], actual[i].finish);
Assert.eq(`Checking result of start for "${exp}"`, exp[0], actual[i].start);
Assert.eq(`Checking result of finish for "${exp}"`, exp[1], actual[i].finish);
});
};
const testData = (pattern: PRegExp, name: string) => ({

@@ -26,52 +27,118 @@ pattern,

const actual = Search.findmany(text, targets);
Assert.eq('', expected.length, actual.length);
Assert.eq(`Checking length of result for "${text}"`, expected.length, actual.length);
Arr.each(expected, (exp, i) => {
Assert.eq('', exp[0], actual[i].start);
Assert.eq('', exp[1], actual[i].finish);
Assert.eq('', exp[2], actual[i].name);
Assert.eq(`Checking result of start for "${exp}"`, exp[0], actual[i].start);
Assert.eq(`Checking result of finish for "${exp}"`, exp[1], actual[i].finish);
Assert.eq(`Checking result of name for "${exp}"`, exp[2], actual[i].name);
});
};
checkAll([], 'eskimo', Pattern.unsafetoken('hi'));
checkAll([[ 1, 7 ]], ' cattle', Pattern.unsafetoken('cattle'));
checkAll([], 'acattle', Pattern.unsafeword('cattle'));
checkAll([[ 1, 7 ]], ' cattle', Pattern.unsafeword('cattle'));
checkAll([], Unicode.zeroWidth + 'dog ', Pattern.safeword('dog'));
it('TINY-10062: checkAll ', () => {
checkAll([], 'eskimo', Pattern.unsafetoken('hi'));
checkAll([[ 1, 7 ]], ' cattle', Pattern.unsafetoken('cattle'));
checkAll([], 'acattle', Pattern.unsafeword('cattle'));
checkAll([[ 1, 7 ]], ' cattle', Pattern.unsafeword('cattle'));
checkAll([], Unicode.zeroWidth + 'dog ', Pattern.safeword('dog'));
checkAll([[ 3, 7 ], [ 10, 14 ]], `no it's i it's done.`, Pattern.unsafetoken(`it's`));
checkAll([[ 0, 12 ]], `catastrophe'`, Pattern.unsafetoken(`catastrophe'`));
checkAll([[ 3, 7 ], [ 10, 14 ]], `no it's i it's done.`, Pattern.unsafetoken(`it's`));
checkAll([[ 0, 12 ]], `catastrophe'`, Pattern.unsafetoken(`catastrophe'`));
checkAll([[ 0, 3 ]], 'sre', Pattern.unsafeword('sre'));
checkAll([[ 0, 3 ]], 'sre ', Pattern.unsafeword('sre'));
checkAll([[ 1, 4 ]], ' sre', Pattern.unsafeword('sre'));
checkAll([[ 1, 4 ]], ' sre ', Pattern.unsafeword('sre'));
checkAll([[ 0, 3 ], [ 4, 7 ]], 'sre sre', Pattern.unsafeword('sre'));
checkAll([[ 1, 4 ], [ 5, 8 ]], ' sre sre', Pattern.unsafeword('sre'));
checkAll([[ 1, 4 ], [ 5, 8 ], [ 9, 12 ]], ' sre sre sre', Pattern.unsafeword('sre'));
checkAll([[ 0, 3 ], [ 4, 7 ], [ 8, 11 ]], 'sre sre sre ', Pattern.unsafeword('sre'));
checkAll([[ 1, 4 ], [ 5, 8 ], [ 9, 12 ]], ' sre sre sre ', Pattern.unsafeword('sre'));
checkAll([[ 0, 3 ]], 'sre', Pattern.unsafeword('sre'));
checkAll([[ 0, 3 ]], 'sre ', Pattern.unsafeword('sre'));
checkAll([[ 1, 4 ]], ' sre', Pattern.unsafeword('sre'));
checkAll([[ 1, 4 ]], ' sre ', Pattern.unsafeword('sre'));
checkAll([[ 0, 3 ], [ 4, 7 ]], 'sre sre', Pattern.unsafeword('sre'));
checkAll([[ 1, 4 ], [ 5, 8 ]], ' sre sre', Pattern.unsafeword('sre'));
checkAll([[ 1, 4 ], [ 5, 8 ], [ 9, 12 ]], ' sre sre sre', Pattern.unsafeword('sre'));
checkAll([[ 0, 3 ], [ 4, 7 ], [ 8, 11 ]], 'sre sre sre ', Pattern.unsafeword('sre'));
checkAll([[ 1, 4 ], [ 5, 8 ], [ 9, 12 ]], ' sre sre sre ', Pattern.unsafeword('sre'));
checkAll([[ 'this '.length, 'this e'.length + Unicode.zeroWidth.length + 'nds'.length ]], 'this e' + Unicode.zeroWidth + 'nds here', Pattern.unsafeword('e' + Unicode.zeroWidth + 'nds'));
checkAll([[ 'this '.length, 'this e'.length + Unicode.zeroWidth.length + 'nds'.length ]], 'this e' + Unicode.zeroWidth + 'nds here', Pattern.unsafeword('e' + Unicode.zeroWidth + 'nds'));
const prefix = Safe.sanitise('[');
const suffix = Safe.sanitise(']');
checkAll([[ 1, 5 ]], ' [wo] and more', Pattern.unsafetoken(prefix + '[^' + suffix + ']*' + suffix));
checkAll([[ 1, 5 ]], ' [wo] and more', Pattern.unsafetoken(Safe.sanitise('[') + '[^' + Safe.sanitise(']') + ']*' + Safe.sanitise(']')));
});
checkMany([], '', []);
checkMany([
[ 1, 3, 'alpha' ]
], ' aa bb cc', [
testData(Pattern.safeword('aa'), 'alpha')
]);
it('TINY-10062: checkMany ', () => {
checkMany([], '', []);
checkMany([
[ 1, 3, 'alpha' ]
], ' aa bb cc', [
testData(Pattern.safeword('aa'), 'alpha')
]);
checkMany([
[ 0, 2, 'alpha' ],
[ 3, 6, 'beta' ],
[ 8, 18, 'gamma' ]
], 'aa bbb abcdefghij', [
testData(Pattern.safeword('bbb'), 'beta'),
testData(Pattern.safeword('abcdefghij'), 'gamma'),
testData(Pattern.safeword('aa'), 'alpha'),
testData(Pattern.safeword('not-there'), 'delta')
]);
checkMany([
[ 0, 3, 'alpha' ],
[ 4, 9, 'beta' ],
[ 10, 16, 'gamma' ],
[ 17, 19, 'delta' ],
], '<p> Hello World</p>', [
testData(Pattern.safeword('<p>'), 'alpha'),
testData(Pattern.safeword('Hello'), 'beta'),
testData(Pattern.safeword('World<'), 'gamma'),
testData(Pattern.safeword('p>'), 'delta'),
]);
checkMany([
[ 0, 8, 'alpha' ],
[ 9, 15, 'beta' ],
[ 16, 18, 'gamma' ],
], '<p>Hello World</p>', [
testData(Pattern.safeword('<p>Hello'), 'alpha'),
testData(Pattern.safeword('World<'), 'beta'),
testData(Pattern.safeword('p>'), 'gamma'),
]);
checkMany([
[ 0, 3, 'alpha' ],
[ 4, 9, 'beta' ],
[ 10, 15, 'gamma' ],
[ 16, 17, 'epsilon' ],
[ 18, 20, 'zeta' ],
], '<p> Hello World </p>', [
testData(Pattern.safeword('<p>'), 'alpha'),
testData(Pattern.safeword('Hello'), 'beta'),
testData(Pattern.safeword('World'), 'gamma'),
testData(Pattern.safeword('<'), 'epsilon'),
testData(Pattern.safeword('p>'), 'zeta'),
]);
checkMany([
[ 0, 8, 'alpha' ],
[ 9, 14, 'beta' ],
[ 15, 16, 'delta' ],
[ 17, 19, 'gamma' ],
], '<p>Hello World </p>', [
testData(Pattern.safeword('<p>Hello'), 'alpha'),
testData(Pattern.safeword('World'), 'beta'),
testData(Pattern.safeword('<'), 'delta'),
testData(Pattern.safeword('p>'), 'gamma'),
]);
checkMany([
[ 7, 16, 'alpha' ],
[ 25, 27, 'beta' ],
], 'Test. [IF:INTEXT]Test2 [/IF]', [
testData(Pattern.safeword('IF:INTEXT'), 'alpha'),
testData(Pattern.safeword('IF'), 'beta'),
]);
checkMany([
[ 8, 10, 'alpha' ],
[ 18, 27, 'beta' ],
], 'Test. [/IF]Test2 [IF:INTEXT]', [
testData(Pattern.safeword('IF'), 'alpha'),
testData(Pattern.safeword('IF:INTEXT'), 'beta'),
]);
checkMany([
[ 0, 2, 'alpha' ],
[ 3, 6, 'beta' ],
[ 8, 18, 'gamma' ]
], 'aa bbb abcdefghij', [
testData(Pattern.safeword('bbb'), 'beta'),
testData(Pattern.safeword('abcdefghij'), 'gamma'),
testData(Pattern.safeword('aa'), 'alpha'),
testData(Pattern.safeword('not-there'), 'delta')
]);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc