highlight-words 1.1.0-beta1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Changelog.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### v1.1.0
2
+
3
+ ---
4
+
5
+ - Switch to new build system
6
+ - Drop umd support
7
+
1
8
  ### v1.0.6
2
9
 
3
10
  ---
package/Readme.md CHANGED
@@ -30,17 +30,17 @@ console.log(chunks);
30
30
  /*
31
31
  [
32
32
  {
33
- id: '62acb210-76dd-4682-b948-8d359a966dcb'
33
+ key: '62acb210-76dd-4682-b948-8d359a966dcb'
34
34
  text: 'The brown fox jumped ',
35
35
  match: false
36
36
  },
37
37
  {
38
- id: '69779adf-6d7c-45ec-ae9b-49d0cb292e28';
38
+ key: '69779adf-6d7c-45ec-ae9b-49d0cb292e28';
39
39
  text: 'over',
40
40
  match: true
41
41
  },
42
42
  {
43
- id: '46c5b7a0-5414-47c5-81ba-2496f33fe2f6';
43
+ key: '46c5b7a0-5414-47c5-81ba-2496f33fe2f6';
44
44
  text: ' the lazy dog',
45
45
  match: false
46
46
  }
@@ -95,4 +95,3 @@ const highlightWords = ({
95
95
  };
96
96
 
97
97
  exports.default = highlightWords;
98
- //# sourceMappingURL=highlight-words.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"highlight-words.min.js","sources":["../src/uid.ts","../src/regexp.ts","../src/clip.ts","../src/index.ts"],"sourcesContent":["// https://github.com/lukeed/uid/blob/master/src/index.js\n/* eslint no-bitwise: 'off' */\n/* eslint no-plusplus: 'off' */\n/* eslint @typescript-eslint/strict-boolean-expressions: 'off' */\nlet IDX = 36;\nlet HEX = '';\nwhile (IDX--) {\n HEX += IDX.toString(36);\n}\n\nexport default function uid(len = 11): string {\n let str = '';\n let num = len;\n while (num--) {\n str += HEX[(Math.random() * 36) | 0];\n }\n return str;\n}\n","import type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\n// We need escape certain characters before creating the RegExp\n// https://github.com/sindresorhus/escape-string-regexp\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`);\n\nconst regexpQuery = ({\n terms,\n matchExactly = false\n}: Readonly<HighlightWords.Query>): string => {\n if (typeof terms !== 'string') {\n throw new TypeError('Expected a string');\n }\n\n const escapedTerms = escapeRegexp(terms.trim());\n return `(${matchExactly ? escapedTerms : escapedTerms.split(' ').join('|')})`;\n};\n\nexport default regexpQuery;\n","/* eslint complexity: [\"error\", { \"max\": 12 }] */\nimport type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\nconst hasProp = <T>(prop: string) => (obj: T) =>\n obj !== null && typeof obj !== 'undefined' && prop in obj;\nconst hasMatch = hasProp<HighlightWords.Chunk>('match');\n\nconst chunkExists = (\n chunk: HighlightWords.Chunk | undefined\n): chunk is HighlightWords.Chunk => typeof chunk !== 'undefined';\n\n/**\n * This provides context around a chunk's text, based on the next and previous chunks.\n * e.g. If we have the string \"The quick brown fox jumped over the lazy dog\",\n * and the search term \"fox jumped\", with a padding of 2, we want to have the end result be:\n * \"... quick brown fox jumped over the ...\"\n * The search term, \"fox jumped\" is left as is, and the left and right chunks, instead of having\n * the text in full, will be clipped.\n */\nexport default function clip({\n curr,\n next,\n prev,\n clipBy = 3\n}: HighlightWords.Clip): string {\n const words = curr.text.split(' ');\n const len = words.length;\n\n // If the current is a match, we leave it alone\n // Or if the clipBy is greater than or equal to the length of the words, there's nothing to clip\n if (curr.match || clipBy >= len) {\n return curr.text;\n }\n\n // If we have a clipBy greater than the length of the words in the current match,\n // it means we can clip the words in the current chunk\n const ellipsis = '...';\n\n if (\n chunkExists(next) &&\n chunkExists(prev) &&\n hasMatch(prev) &&\n hasMatch(next)\n ) {\n // Both the previous and the next chunks are a match\n // Let's check if we have enough words to clip by on both sides\n if (len > clipBy * 2) {\n return [\n ...words.slice(0, clipBy),\n ellipsis,\n ...words.slice(-clipBy)\n ].join(' ');\n }\n\n return curr.text;\n }\n\n // We start to check the next and previous matches in order to\n // properly position the elipsis\n if (chunkExists(next) && hasMatch(next)) {\n // The chunk right after this one is a match\n // So we need the elipsis at the start of the returned text\n // so that it sticks correctly to the next (match)'s text\n return [ellipsis, ...words.slice(-clipBy)].join(' ');\n }\n\n if (chunkExists(prev) && hasMatch(prev)) {\n // The chunk right before this one is a match\n // So we need the elipsis at the end of the returned text\n // so that it sticks correctly to the previous (match)'s text\n return [...words.slice(0, clipBy), ellipsis].join(' ');\n }\n\n // If we made it this far, just return the text\n return curr.text;\n}\n","import uid from './uid';\nimport regexpQuery from './regexp'; // eslint-disable-line import/no-cycle\nimport clip from './clip'; // eslint-disable-line import/no-cycle\n\n/* eslint-disable import/no-unused-modules */\ndeclare namespace HighlightWords {\n export interface Chunk {\n key: string;\n text: string;\n match: boolean;\n }\n\n export interface Options {\n text: string;\n query: string;\n clipBy?: number;\n matchExactly?: boolean;\n }\n\n export interface Clip {\n curr: Chunk;\n next?: Chunk;\n prev?: Chunk;\n clipBy?: number;\n }\n\n export interface Query {\n terms: string;\n matchExactly?: boolean;\n }\n}\n\nexport { HighlightWords };\n/* eslint-enable import/no-unused-modules */\n\nconst hasLength = (str: string): boolean => str.length > 0;\n\n/**\n * Split a text into chunks denoting which are a match and which are not based on a user search term.\n * @param text String The text to split.\n * @param query String The query to split by. This can contain multiple words.\n * @param clipBy Number Clip the non-matches by a certain number of words to provide context around the matches.\n * @param matchExactly Boolean If we have multiple words in the query, we will match any of the words if exact is false. For example, searching for \"brown fox\" in \"the brown cute fox\" will yield both \"brown\" and \"fox\" as matches. While if exact is true, the same search will return no results.\n */\nconst highlightWords = ({\n text,\n query,\n clipBy,\n matchExactly = false\n}: Readonly<HighlightWords.Options>): HighlightWords.Chunk[] => {\n // Let's make sure that the user cannot pass in just a bunch of spaces\n const safeQuery = query.trim();\n\n if (safeQuery === '') {\n return [\n {\n key: uid(),\n text,\n match: false\n }\n ];\n }\n\n const searchRegexp = new RegExp(\n regexpQuery({ terms: safeQuery, matchExactly }),\n 'ig'\n );\n\n type ReadonlyChunk = Readonly<HighlightWords.Chunk>; // eslint-disable-line @typescript-eslint/no-type-alias\n\n return text\n .split(searchRegexp) // Split the entire thing into an array of matches and non-matches\n .filter(hasLength) // Filter any matches that have the text with length of 0\n .map((str) => ({\n // Compose the object for a match\n key: uid(),\n text: str,\n match: matchExactly\n ? str.toLowerCase() === safeQuery.toLowerCase()\n : searchRegexp.test(str)\n }))\n .map((chunk: ReadonlyChunk, index, chunks: readonly ReadonlyChunk[]) => ({\n // For each chunk, clip the text if needed\n ...chunk, // All the props first\n ...(typeof clipBy === 'number' && {\n // We only overwrite the text if there is a clip\n text: clip({\n curr: chunk, // We need the current chunk\n ...(index < chunks.length - 1 && { next: chunks[index + 1] }), // If this wasn't the last chunk, set the next chunk\n ...(index > 0 && { prev: chunks[index - 1] }), // If this wasn't the first chunk, set the previous chunk\n clipBy\n })\n })\n }));\n};\n\nexport default highlightWords;\n"],"names":[],"mappings":";;;;AAIA,IAAI,MAAM;AACV,IAAI,MAAM;AACV,OAAO;AACL,SAAO,IAAI,SAAS;AAAA;aAGM,MAAM;AAChC,MAAI,MAAM;AACV,MAAI,MAAM;AACV,SAAO;AACL,WAAO,IAAK,KAAK,WAAW,KAAM;AAAA;AAEpC,SAAO;AAAA;;ACZT,MAAM,eAAe,CAAC,SACpB,KAAK,QAAQ,wBAAwB,CAAC,SAAiB,KAAK;AAE9D,MAAM,cAAc,CAAC;AAAA,EACnB;AAAA,EACA,eAAe;AAAA;AAEf,MAAI,OAAO,UAAU;AACnB,UAAM,IAAI,UAAU;AAAA;AAGtB,QAAM,eAAe,aAAa,MAAM;AACxC,SAAO,IAAI,eAAe,eAAe,aAAa,MAAM,KAAK,KAAK;AAAA;;ACbxE,MAAM,UAAU,CAAI,SAAiB,CAAC,QACpC,QAAQ,QAAQ,OAAO,QAAQ,eAAe,QAAQ;AACxD,MAAM,WAAW,QAA8B;AAE/C,MAAM,cAAc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AA,MACT,MAAM;AAAA,OACF,QAAQ,OAAO,SAAS,KAAK,CAAE,MAAM,OAAO,QAAQ,MACpD,QAAQ,KAAK,CAAE,MAAM,OAAO,QAAQ,MAH/B;AAAA,MAIT;AAAA;AAAA;AAAA;;;;"}
@@ -1,2 +1,2 @@
1
1
  let h=36,u="";for(;h--;)u+=h.toString(36);function p(e=11){let t="",n=e;for(;n--;)t+=u[Math.random()*36|0];return t}const m=e=>e.replace(/[|\\{}()[\]^$+*?.-]/g,t=>`\\${t}`),d=({terms:e,matchExactly:t=!1})=>{if(typeof e!="string")throw new TypeError("Expected a string");const n=m(e.trim());return`(${t?n:n.split(" ").join("|")})`},w=e=>t=>t!==null&&typeof t!="undefined"&&e in t,f=w("match"),c=e=>typeof e!="undefined";function x({curr:e,next:t,prev:n,clipBy:r=3}){const o=e.text.split(" "),i=o.length;if(e.match||r>=i)return e.text;const s="...";return c(t)&&c(n)&&f(n)&&f(t)?i>r*2?[...o.slice(0,r),s,...o.slice(-r)].join(" "):e.text:c(t)&&f(t)?[s,...o.slice(-r)].join(" "):c(n)&&f(n)?[...o.slice(0,r),s].join(" "):e.text}var a=Object.assign;const E=e=>e.length>0,j=({text:e,query:t,clipBy:n,matchExactly:r=!1})=>{const o=t.trim();if(o==="")return[{key:p(),text:e,match:!1}];const i=new RegExp(d({terms:o,matchExactly:r}),"ig");return e.split(i).filter(E).map(s=>({key:p(),text:s,match:r?s.toLowerCase()===o.toLowerCase():i.test(s)})).map((s,l,g)=>a(a({},s),typeof n=="number"&&{text:x(a(a(a({curr:s},l<g.length-1&&{next:g[l+1]}),l>0&&{prev:g[l-1]}),{clipBy:n}))}))};export default j;
2
- //# sourceMappingURL=highlight-words.min.js.map
2
+ //# sourceMappingURL=highlight-words.min.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"highlight-words.min.mjs","sources":["../src/uid.ts","../src/regexp.ts","../src/clip.ts","../src/index.ts"],"sourcesContent":["// https://github.com/lukeed/uid/blob/master/src/index.js\n/* eslint no-bitwise: 'off' */\n/* eslint no-plusplus: 'off' */\n/* eslint @typescript-eslint/strict-boolean-expressions: 'off' */\nlet IDX = 36;\nlet HEX = '';\nwhile (IDX--) {\n HEX += IDX.toString(36);\n}\n\nexport default function uid(len = 11): string {\n let str = '';\n let num = len;\n while (num--) {\n str += HEX[(Math.random() * 36) | 0];\n }\n return str;\n}\n","import type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\n// We need escape certain characters before creating the RegExp\n// https://github.com/sindresorhus/escape-string-regexp\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`);\n\nconst regexpQuery = ({\n terms,\n matchExactly = false\n}: Readonly<HighlightWords.Query>): string => {\n if (typeof terms !== 'string') {\n throw new TypeError('Expected a string');\n }\n\n const escapedTerms = escapeRegexp(terms.trim());\n return `(${matchExactly ? escapedTerms : escapedTerms.split(' ').join('|')})`;\n};\n\nexport default regexpQuery;\n","/* eslint complexity: [\"error\", { \"max\": 12 }] */\nimport type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\nconst hasProp = <T>(prop: string) => (obj: T) =>\n obj !== null && typeof obj !== 'undefined' && prop in obj;\nconst hasMatch = hasProp<HighlightWords.Chunk>('match');\n\nconst chunkExists = (\n chunk: HighlightWords.Chunk | undefined\n): chunk is HighlightWords.Chunk => typeof chunk !== 'undefined';\n\n/**\n * This provides context around a chunk's text, based on the next and previous chunks.\n * e.g. If we have the string \"The quick brown fox jumped over the lazy dog\",\n * and the search term \"fox jumped\", with a padding of 2, we want to have the end result be:\n * \"... quick brown fox jumped over the ...\"\n * The search term, \"fox jumped\" is left as is, and the left and right chunks, instead of having\n * the text in full, will be clipped.\n */\nexport default function clip({\n curr,\n next,\n prev,\n clipBy = 3\n}: HighlightWords.Clip): string {\n const words = curr.text.split(' ');\n const len = words.length;\n\n // If the current is a match, we leave it alone\n // Or if the clipBy is greater than or equal to the length of the words, there's nothing to clip\n if (curr.match || clipBy >= len) {\n return curr.text;\n }\n\n // If we have a clipBy greater than the length of the words in the current match,\n // it means we can clip the words in the current chunk\n const ellipsis = '...';\n\n if (\n chunkExists(next) &&\n chunkExists(prev) &&\n hasMatch(prev) &&\n hasMatch(next)\n ) {\n // Both the previous and the next chunks are a match\n // Let's check if we have enough words to clip by on both sides\n if (len > clipBy * 2) {\n return [\n ...words.slice(0, clipBy),\n ellipsis,\n ...words.slice(-clipBy)\n ].join(' ');\n }\n\n return curr.text;\n }\n\n // We start to check the next and previous matches in order to\n // properly position the elipsis\n if (chunkExists(next) && hasMatch(next)) {\n // The chunk right after this one is a match\n // So we need the elipsis at the start of the returned text\n // so that it sticks correctly to the next (match)'s text\n return [ellipsis, ...words.slice(-clipBy)].join(' ');\n }\n\n if (chunkExists(prev) && hasMatch(prev)) {\n // The chunk right before this one is a match\n // So we need the elipsis at the end of the returned text\n // so that it sticks correctly to the previous (match)'s text\n return [...words.slice(0, clipBy), ellipsis].join(' ');\n }\n\n // If we made it this far, just return the text\n return curr.text;\n}\n","import uid from './uid';\nimport regexpQuery from './regexp'; // eslint-disable-line import/no-cycle\nimport clip from './clip'; // eslint-disable-line import/no-cycle\n\n/* eslint-disable import/no-unused-modules */\ndeclare namespace HighlightWords {\n export interface Chunk {\n key: string;\n text: string;\n match: boolean;\n }\n\n export interface Options {\n text: string;\n query: string;\n clipBy?: number;\n matchExactly?: boolean;\n }\n\n export interface Clip {\n curr: Chunk;\n next?: Chunk;\n prev?: Chunk;\n clipBy?: number;\n }\n\n export interface Query {\n terms: string;\n matchExactly?: boolean;\n }\n}\n\nexport { HighlightWords };\n/* eslint-enable import/no-unused-modules */\n\nconst hasLength = (str: string): boolean => str.length > 0;\n\n/**\n * Split a text into chunks denoting which are a match and which are not based on a user search term.\n * @param text String The text to split.\n * @param query String The query to split by. This can contain multiple words.\n * @param clipBy Number Clip the non-matches by a certain number of words to provide context around the matches.\n * @param matchExactly Boolean If we have multiple words in the query, we will match any of the words if exact is false. For example, searching for \"brown fox\" in \"the brown cute fox\" will yield both \"brown\" and \"fox\" as matches. While if exact is true, the same search will return no results.\n */\nconst highlightWords = ({\n text,\n query,\n clipBy,\n matchExactly = false\n}: Readonly<HighlightWords.Options>): HighlightWords.Chunk[] => {\n // Let's make sure that the user cannot pass in just a bunch of spaces\n const safeQuery = query.trim();\n\n if (safeQuery === '') {\n return [\n {\n key: uid(),\n text,\n match: false\n }\n ];\n }\n\n const searchRegexp = new RegExp(\n regexpQuery({ terms: safeQuery, matchExactly }),\n 'ig'\n );\n\n type ReadonlyChunk = Readonly<HighlightWords.Chunk>; // eslint-disable-line @typescript-eslint/no-type-alias\n\n return text\n .split(searchRegexp) // Split the entire thing into an array of matches and non-matches\n .filter(hasLength) // Filter any matches that have the text with length of 0\n .map((str) => ({\n // Compose the object for a match\n key: uid(),\n text: str,\n match: matchExactly\n ? str.toLowerCase() === safeQuery.toLowerCase()\n : searchRegexp.test(str)\n }))\n .map((chunk: ReadonlyChunk, index, chunks: readonly ReadonlyChunk[]) => ({\n // For each chunk, clip the text if needed\n ...chunk, // All the props first\n ...(typeof clipBy === 'number' && {\n // We only overwrite the text if there is a clip\n text: clip({\n curr: chunk, // We need the current chunk\n ...(index < chunks.length - 1 && { next: chunks[index + 1] }), // If this wasn't the last chunk, set the next chunk\n ...(index > 0 && { prev: chunks[index - 1] }), // If this wasn't the first chunk, set the previous chunk\n clipBy\n })\n })\n }));\n};\n\nexport default highlightWords;\n"],"names":[],"mappings":"AAIA,IAAI,MAAM;AACV,IAAI,MAAM;AACV,OAAO;AACL,SAAO,IAAI,SAAS;AAAA;aAGM,MAAM;AAChC,MAAI,MAAM;AACV,MAAI,MAAM;AACV,SAAO;AACL,WAAO,IAAK,KAAK,WAAW,KAAM;AAAA;AAEpC,SAAO;AAAA;;ACZT,MAAM,eAAe,CAAC,SACpB,KAAK,QAAQ,wBAAwB,CAAC,SAAiB,KAAK;AAE9D,MAAM,cAAc,CAAC;AAAA,EACnB;AAAA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AI,OACvB,YAAY,CAAE,OAAO,WAAW,gBAChC;AAKF,SAAO,KACJ,MAAM,cACN,OAAO,WACP,IAAI,CAAC;AAAS,IAEb,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO,eACH,IAAI,kBAAkB,UAAU,gBAChC,aAAa,KAAK;AAAA,MAEvB,IAAI,CAAC,OAAsB,OAAO,WAAsC,sBAEpE,QACC,OAAO,WAAW,YAAY;AAAA,IAEhC,MAAM,KAAK;AAAA,MACT,MAAM;AAAA,OACF,QAAQ,OAAO,SAAS,KAAK,CAAE,MAAM,OAAO,QAAQ,MACpD,QAAQ,KAAK,CAAE,MAAM,OAAO,QAAQ,MAH/B;AAAA,MAIT;AAAA;AAAA;AAAA;;;;"}
@@ -91,4 +91,3 @@ const highlightWords = ({
91
91
  };
92
92
 
93
93
  export default highlightWords;
94
- //# sourceMappingURL=highlight-words.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "highlight-words",
3
- "version": "1.1.0-beta1",
3
+ "version": "1.1.1",
4
4
  "description": "Split a piece text into multiple chunks based on a search query, allowing you to highlight the matches.",
5
5
  "engines": {
6
6
  "node": ">= 12",
@@ -30,10 +30,16 @@
30
30
  "dist",
31
31
  "coverage"
32
32
  ],
33
- "main": "dist/lib/index.js",
34
- "module": "dist/lib-esm/index.js",
35
- "browser": "dist/bundles/highlight-words.js",
33
+ "type": "commonjs",
36
34
  "typings": "dist/highlight-words.d.ts",
35
+ "main": "dist/highlight-words.js",
36
+ "module": "dist/highlight-words.mjs",
37
+ "exports": {
38
+ ".": {
39
+ "require": "./dist/highlight-words.js",
40
+ "default": "./dist/highlight-words.mjs"
41
+ }
42
+ },
37
43
  "scripts": {
38
44
  "prebuild": "cross-env rimraf dist",
39
45
  "build": "rollup -c",
@@ -42,7 +48,8 @@
42
48
  "lint": "eslint src --ext .ts",
43
49
  "format": "prettier --write \"src/**/*.ts\"",
44
50
  "test": "jest",
45
- "test:mutations": "stryker run"
51
+ "test:mutations": "stryker run",
52
+ "prepublishOnly": "npm-run-all test typecheck lint build"
46
53
  },
47
54
  "devDependencies": {
48
55
  "@babel/core": "^7.12.13",
@@ -66,6 +73,7 @@
66
73
  "jest": "^26.6.3",
67
74
  "jest-watch-typeahead": "^0.6.1",
68
75
  "lint-staged": "^10.5.4",
76
+ "npm-run-all": "^4.1.5",
69
77
  "precise-commits": "^1.0.2",
70
78
  "prettier": "^2.2.1",
71
79
  "rimraf": "^3.0.2",
@@ -1,102 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define(factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.HighlightWords = factory());
5
- }(this, (function () { 'use strict';
6
-
7
- let IDX = 36;
8
- let HEX = "";
9
- while (IDX--) {
10
- HEX += IDX.toString(36);
11
- }
12
- function uid(len = 11) {
13
- let str = "";
14
- let num = len;
15
- while (num--) {
16
- str += HEX[Math.random() * 36 | 0];
17
- }
18
- return str;
19
- }
20
-
21
- const escapeRegexp = (term) => term.replace(/[|\\{}()[\]^$+*?.-]/g, (char) => `\\${char}`);
22
- const regexpQuery = ({
23
- terms,
24
- matchExactly = false
25
- }) => {
26
- if (typeof terms !== "string") {
27
- throw new TypeError("Expected a string");
28
- }
29
- const escapedTerms = escapeRegexp(terms.trim());
30
- return `(${matchExactly ? escapedTerms : escapedTerms.split(" ").join("|")})`;
31
- };
32
-
33
- const hasProp = (prop) => (obj) => obj !== null && typeof obj !== "undefined" && prop in obj;
34
- const hasMatch = hasProp("match");
35
- const chunkExists = (chunk) => typeof chunk !== "undefined";
36
- function clip({
37
- curr,
38
- next,
39
- prev,
40
- clipBy = 3
41
- }) {
42
- const words = curr.text.split(" ");
43
- const len = words.length;
44
- if (curr.match || clipBy >= len) {
45
- return curr.text;
46
- }
47
- const ellipsis = "...";
48
- if (chunkExists(next) && chunkExists(prev) && hasMatch(prev) && hasMatch(next)) {
49
- if (len > clipBy * 2) {
50
- return [
51
- ...words.slice(0, clipBy),
52
- ellipsis,
53
- ...words.slice(-clipBy)
54
- ].join(" ");
55
- }
56
- return curr.text;
57
- }
58
- if (chunkExists(next) && hasMatch(next)) {
59
- return [ellipsis, ...words.slice(-clipBy)].join(" ");
60
- }
61
- if (chunkExists(prev) && hasMatch(prev)) {
62
- return [...words.slice(0, clipBy), ellipsis].join(" ");
63
- }
64
- return curr.text;
65
- }
66
-
67
- var __assign = Object.assign;
68
- const hasLength = (str) => str.length > 0;
69
- const highlightWords = ({
70
- text,
71
- query,
72
- clipBy,
73
- matchExactly = false
74
- }) => {
75
- const safeQuery = query.trim();
76
- if (safeQuery === "") {
77
- return [
78
- {
79
- key: uid(),
80
- text,
81
- match: false
82
- }
83
- ];
84
- }
85
- const searchRegexp = new RegExp(regexpQuery({terms: safeQuery, matchExactly}), "ig");
86
- return text.split(searchRegexp).filter(hasLength).map((str) => ({
87
- key: uid(),
88
- text: str,
89
- match: matchExactly ? str.toLowerCase() === safeQuery.toLowerCase() : searchRegexp.test(str)
90
- })).map((chunk, index, chunks) => __assign(__assign({}, chunk), typeof clipBy === "number" && {
91
- text: clip(__assign(__assign(__assign({
92
- curr: chunk
93
- }, index < chunks.length - 1 && {next: chunks[index + 1]}), index > 0 && {prev: chunks[index - 1]}), {
94
- clipBy
95
- }))
96
- }));
97
- };
98
-
99
- return highlightWords;
100
-
101
- })));
102
- //# sourceMappingURL=highlight-words.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"highlight-words.js","sources":["../../src/uid.ts","../../src/regexp.ts","../../src/clip.ts","../../src/index.ts"],"sourcesContent":["// https://github.com/lukeed/uid/blob/master/src/index.js\n/* eslint no-bitwise: 'off' */\n/* eslint no-plusplus: 'off' */\n/* eslint @typescript-eslint/strict-boolean-expressions: 'off' */\nlet IDX = 36;\nlet HEX = '';\nwhile (IDX--) {\n HEX += IDX.toString(36);\n}\n\nexport default function uid(len = 11): string {\n let str = '';\n let num = len;\n while (num--) {\n str += HEX[(Math.random() * 36) | 0];\n }\n return str;\n}\n","import type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\n// We need escape certain characters before creating the RegExp\n// https://github.com/sindresorhus/escape-string-regexp\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`);\n\nconst regexpQuery = ({\n terms,\n matchExactly = false\n}: Readonly<HighlightWords.Query>): string => {\n if (typeof terms !== 'string') {\n throw new TypeError('Expected a string');\n }\n\n const escapedTerms = escapeRegexp(terms.trim());\n return `(${matchExactly ? escapedTerms : escapedTerms.split(' ').join('|')})`;\n};\n\nexport default regexpQuery;\n","/* eslint complexity: [\"error\", { \"max\": 12 }] */\nimport type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\nconst hasProp = <T>(prop: string) => (obj: T) =>\n obj !== null && typeof obj !== 'undefined' && prop in obj;\nconst hasMatch = hasProp<HighlightWords.Chunk>('match');\n\nconst chunkExists = (\n chunk: HighlightWords.Chunk | undefined\n): chunk is HighlightWords.Chunk => typeof chunk !== 'undefined';\n\n/**\n * This provides context around a chunk's text, based on the next and previous chunks.\n * e.g. If we have the string \"The quick brown fox jumped over the lazy dog\",\n * and the search term \"fox jumped\", with a padding of 2, we want to have the end result be:\n * \"... quick brown fox jumped over the ...\"\n * The search term, \"fox jumped\" is left as is, and the left and right chunks, instead of having\n * the text in full, will be clipped.\n */\nexport default function clip({\n curr,\n next,\n prev,\n clipBy = 3\n}: HighlightWords.Clip): string {\n const words = curr.text.split(' ');\n const len = words.length;\n\n // If the current is a match, we leave it alone\n // Or if the clipBy is greater than or equal to the length of the words, there's nothing to clip\n if (curr.match || clipBy >= len) {\n return curr.text;\n }\n\n // If we have a clipBy greater than the length of the words in the current match,\n // it means we can clip the words in the current chunk\n const ellipsis = '...';\n\n if (\n chunkExists(next) &&\n chunkExists(prev) &&\n hasMatch(prev) &&\n hasMatch(next)\n ) {\n // Both the previous and the next chunks are a match\n // Let's check if we have enough words to clip by on both sides\n if (len > clipBy * 2) {\n return [\n ...words.slice(0, clipBy),\n ellipsis,\n ...words.slice(-clipBy)\n ].join(' ');\n }\n\n return curr.text;\n }\n\n // We start to check the next and previous matches in order to\n // properly position the elipsis\n if (chunkExists(next) && hasMatch(next)) {\n // The chunk right after this one is a match\n // So we need the elipsis at the start of the returned text\n // so that it sticks correctly to the next (match)'s text\n return [ellipsis, ...words.slice(-clipBy)].join(' ');\n }\n\n if (chunkExists(prev) && hasMatch(prev)) {\n // The chunk right before this one is a match\n // So we need the elipsis at the end of the returned text\n // so that it sticks correctly to the previous (match)'s text\n return [...words.slice(0, clipBy), ellipsis].join(' ');\n }\n\n // If we made it this far, just return the text\n return curr.text;\n}\n","import uid from './uid';\nimport regexpQuery from './regexp'; // eslint-disable-line import/no-cycle\nimport clip from './clip'; // eslint-disable-line import/no-cycle\n\n/* eslint-disable import/no-unused-modules */\ndeclare namespace HighlightWords {\n export interface Chunk {\n key: string;\n text: string;\n match: boolean;\n }\n\n export interface Options {\n text: string;\n query: string;\n clipBy?: number;\n matchExactly?: boolean;\n }\n\n export interface Clip {\n curr: Chunk;\n next?: Chunk;\n prev?: Chunk;\n clipBy?: number;\n }\n\n export interface Query {\n terms: string;\n matchExactly?: boolean;\n }\n}\n\nexport { HighlightWords };\n/* eslint-enable import/no-unused-modules */\n\nconst hasLength = (str: string): boolean => str.length > 0;\n\n/**\n * Split a text into chunks denoting which are a match and which are not based on a user search term.\n * @param text String The text to split.\n * @param query String The query to split by. This can contain multiple words.\n * @param clipBy Number Clip the non-matches by a certain number of words to provide context around the matches.\n * @param matchExactly Boolean If we have multiple words in the query, we will match any of the words if exact is false. For example, searching for \"brown fox\" in \"the brown cute fox\" will yield both \"brown\" and \"fox\" as matches. While if exact is true, the same search will return no results.\n */\nconst highlightWords = ({\n text,\n query,\n clipBy,\n matchExactly = false\n}: Readonly<HighlightWords.Options>): HighlightWords.Chunk[] => {\n // Let's make sure that the user cannot pass in just a bunch of spaces\n const safeQuery = query.trim();\n\n if (safeQuery === '') {\n return [\n {\n key: uid(),\n text,\n match: false\n }\n ];\n }\n\n const searchRegexp = new RegExp(\n regexpQuery({ terms: safeQuery, matchExactly }),\n 'ig'\n );\n\n type ReadonlyChunk = Readonly<HighlightWords.Chunk>; // eslint-disable-line @typescript-eslint/no-type-alias\n\n return text\n .split(searchRegexp) // Split the entire thing into an array of matches and non-matches\n .filter(hasLength) // Filter any matches that have the text with length of 0\n .map((str) => ({\n // Compose the object for a match\n key: uid(),\n text: str,\n match: matchExactly\n ? str.toLowerCase() === safeQuery.toLowerCase()\n : searchRegexp.test(str)\n }))\n .map((chunk: ReadonlyChunk, index, chunks: readonly ReadonlyChunk[]) => ({\n // For each chunk, clip the text if needed\n ...chunk, // All the props first\n ...(typeof clipBy === 'number' && {\n // We only overwrite the text if there is a clip\n text: clip({\n curr: chunk, // We need the current chunk\n ...(index < chunks.length - 1 && { next: chunks[index + 1] }), // If this wasn't the last chunk, set the next chunk\n ...(index > 0 && { prev: chunks[index - 1] }), // If this wasn't the first chunk, set the previous chunk\n clipBy\n })\n })\n }));\n};\n\nexport default highlightWords;\n"],"names":[],"mappings":";;;;;;EAIA,IAAI,MAAM;EACV,IAAI,MAAM;EACV,OAAO;EACL,SAAO,IAAI,SAAS;EAAA;eAGM,MAAM;EAChC,MAAI,MAAM;EACV,MAAI,MAAM;EACV,SAAO;EACL,WAAO,IAAK,KAAK,WAAW,KAAM;EAAA;EAEpC,SAAO;EAAA;;ECZT,MAAM,eAAe,CAAC,SACpB,KAAK,QAAQ,wBAAwB,CAAC,SAAiB,KAAK;EAE9D,MAAM,cAAc,CAAC;EAAA,EACnB;EAAA,EACA,eAAe;EAAA;EAEf,MAAI,OAAO,UAAU;EACnB,UAAM,IAAI,UAAU;EAAA;EAGtB,QAAM,eAAe,aAAa,MAAM;EACxC,SAAO,IAAI,eAAe,eAAe,aAAa,MAAM,KAAK,KAAK;EAAA;;ECbxE,MAAM,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aAAa,KAAK;EAAA,MAEvB,IAAI,CAAC,OAAsB,OAAO,WAAsC,sBAEpE,QACC,OAAO,WAAW,YAAY;EAAA,IAEhC,MAAM,KAAK;EAAA,MACT,MAAM;EAAA,OACF,QAAQ,OAAO,SAAS,KAAK,CAAE,MAAM,OAAO,QAAQ,MACpD,QAAQ,KAAK,CAAE,MAAM,OAAO,QAAQ,MAH/B;EAAA,MAIT;EAAA;EAAA;EAAA;;;;;;;;"}
@@ -1,2 +0,0 @@
1
- (function(r,f){typeof exports=="object"&&typeof module!="undefined"?module.exports=f():typeof define=="function"&&define.amd?define(f):(r=typeof globalThis!="undefined"?globalThis:r||self,r.HighlightWords=f())})(this,function(){"use strict";let r=36,f="";for(;r--;)f+=r.toString(36);function p(e=11){let t="",n=e;for(;n--;)t+=f[Math.random()*36|0];return t}const d=e=>e.replace(/[|\\{}()[\]^$+*?.-]/g,t=>`\\${t}`),m=({terms:e,matchExactly:t=!1})=>{if(typeof e!="string")throw new TypeError("Expected a string");const n=d(e.trim());return`(${t?n:n.split(" ").join("|")})`},a=(e=>t=>t!==null&&typeof t!="undefined"&&e in t)("match"),u=e=>typeof e!="undefined";function w({curr:e,next:t,prev:n,clipBy:i=3}){const o=e.text.split(" "),l=o.length;if(e.match||i>=l)return e.text;const s="...";return u(t)&&u(n)&&a(n)&&a(t)?l>i*2?[...o.slice(0,i),s,...o.slice(-i)].join(" "):e.text:u(t)&&a(t)?[s,...o.slice(-i)].join(" "):u(n)&&a(n)?[...o.slice(0,i),s].join(" "):e.text}var h=Object.assign;const x=e=>e.length>0;return({text:e,query:t,clipBy:n,matchExactly:i=!1})=>{const o=t.trim();if(o==="")return[{key:p(),text:e,match:!1}];const l=new RegExp(m({terms:o,matchExactly:i}),"ig");return e.split(l).filter(x).map(s=>({key:p(),text:s,match:i?s.toLowerCase()===o.toLowerCase():l.test(s)})).map((s,c,g)=>h(h({},s),typeof n=="number"&&{text:w(h(h(h({curr:s},c<g.length-1&&{next:g[c+1]}),c>0&&{prev:g[c-1]}),{clipBy:n}))}))}});
2
- //# sourceMappingURL=highlight-words.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"highlight-words.min.js","sources":["../../src/uid.ts","../../src/regexp.ts","../../src/clip.ts","../../src/index.ts"],"sourcesContent":["// https://github.com/lukeed/uid/blob/master/src/index.js\n/* eslint no-bitwise: 'off' */\n/* eslint no-plusplus: 'off' */\n/* eslint @typescript-eslint/strict-boolean-expressions: 'off' */\nlet IDX = 36;\nlet HEX = '';\nwhile (IDX--) {\n HEX += IDX.toString(36);\n}\n\nexport default function uid(len = 11): string {\n let str = '';\n let num = len;\n while (num--) {\n str += HEX[(Math.random() * 36) | 0];\n }\n return str;\n}\n","import type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\n// We need escape certain characters before creating the RegExp\n// https://github.com/sindresorhus/escape-string-regexp\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`);\n\nconst regexpQuery = ({\n terms,\n matchExactly = false\n}: Readonly<HighlightWords.Query>): string => {\n if (typeof terms !== 'string') {\n throw new TypeError('Expected a string');\n }\n\n const escapedTerms = escapeRegexp(terms.trim());\n return `(${matchExactly ? escapedTerms : escapedTerms.split(' ').join('|')})`;\n};\n\nexport default regexpQuery;\n","/* eslint complexity: [\"error\", { \"max\": 12 }] */\nimport type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\nconst hasProp = <T>(prop: string) => (obj: T) =>\n obj !== null && typeof obj !== 'undefined' && prop in obj;\nconst hasMatch = hasProp<HighlightWords.Chunk>('match');\n\nconst chunkExists = (\n chunk: HighlightWords.Chunk | undefined\n): chunk is HighlightWords.Chunk => typeof chunk !== 'undefined';\n\n/**\n * This provides context around a chunk's text, based on the next and previous chunks.\n * e.g. If we have the string \"The quick brown fox jumped over the lazy dog\",\n * and the search term \"fox jumped\", with a padding of 2, we want to have the end result be:\n * \"... quick brown fox jumped over the ...\"\n * The search term, \"fox jumped\" is left as is, and the left and right chunks, instead of having\n * the text in full, will be clipped.\n */\nexport default function clip({\n curr,\n next,\n prev,\n clipBy = 3\n}: HighlightWords.Clip): string {\n const words = curr.text.split(' ');\n const len = words.length;\n\n // If the current is a match, we leave it alone\n // Or if the clipBy is greater than or equal to the length of the words, there's nothing to clip\n if (curr.match || clipBy >= len) {\n return curr.text;\n }\n\n // If we have a clipBy greater than the length of the words in the current match,\n // it means we can clip the words in the current chunk\n const ellipsis = '...';\n\n if (\n chunkExists(next) &&\n chunkExists(prev) &&\n hasMatch(prev) &&\n hasMatch(next)\n ) {\n // Both the previous and the next chunks are a match\n // Let's check if we have enough words to clip by on both sides\n if (len > clipBy * 2) {\n return [\n ...words.slice(0, clipBy),\n ellipsis,\n ...words.slice(-clipBy)\n ].join(' ');\n }\n\n return curr.text;\n }\n\n // We start to check the next and previous matches in order to\n // properly position the elipsis\n if (chunkExists(next) && hasMatch(next)) {\n // The chunk right after this one is a match\n // So we need the elipsis at the start of the returned text\n // so that it sticks correctly to the next (match)'s text\n return [ellipsis, ...words.slice(-clipBy)].join(' ');\n }\n\n if (chunkExists(prev) && hasMatch(prev)) {\n // The chunk right before this one is a match\n // So we need the elipsis at the end of the returned text\n // so that it sticks correctly to the previous (match)'s text\n return [...words.slice(0, clipBy), ellipsis].join(' ');\n }\n\n // If we made it this far, just return the text\n return curr.text;\n}\n","import uid from './uid';\nimport regexpQuery from './regexp'; // eslint-disable-line import/no-cycle\nimport clip from './clip'; // eslint-disable-line import/no-cycle\n\n/* eslint-disable import/no-unused-modules */\ndeclare namespace HighlightWords {\n export interface Chunk {\n key: string;\n text: string;\n match: boolean;\n }\n\n export interface Options {\n text: string;\n query: string;\n clipBy?: number;\n matchExactly?: boolean;\n }\n\n export interface Clip {\n curr: Chunk;\n next?: Chunk;\n prev?: Chunk;\n clipBy?: number;\n }\n\n export interface Query {\n terms: string;\n matchExactly?: boolean;\n }\n}\n\nexport { HighlightWords };\n/* eslint-enable import/no-unused-modules */\n\nconst hasLength = (str: string): boolean => str.length > 0;\n\n/**\n * Split a text into chunks denoting which are a match and which are not based on a user search term.\n * @param text String The text to split.\n * @param query String The query to split by. This can contain multiple words.\n * @param clipBy Number Clip the non-matches by a certain number of words to provide context around the matches.\n * @param matchExactly Boolean If we have multiple words in the query, we will match any of the words if exact is false. For example, searching for \"brown fox\" in \"the brown cute fox\" will yield both \"brown\" and \"fox\" as matches. While if exact is true, the same search will return no results.\n */\nconst highlightWords = ({\n text,\n query,\n clipBy,\n matchExactly = false\n}: Readonly<HighlightWords.Options>): HighlightWords.Chunk[] => {\n // Let's make sure that the user cannot pass in just a bunch of spaces\n const safeQuery = query.trim();\n\n if (safeQuery === '') {\n return [\n {\n key: uid(),\n text,\n match: false\n }\n ];\n }\n\n const searchRegexp = new RegExp(\n regexpQuery({ terms: safeQuery, matchExactly }),\n 'ig'\n );\n\n type ReadonlyChunk = Readonly<HighlightWords.Chunk>; // eslint-disable-line @typescript-eslint/no-type-alias\n\n return text\n .split(searchRegexp) // Split the entire thing into an array of matches and non-matches\n .filter(hasLength) // Filter any matches that have the text with length of 0\n .map((str) => ({\n // Compose the object for a match\n key: uid(),\n text: str,\n match: matchExactly\n ? str.toLowerCase() === safeQuery.toLowerCase()\n : searchRegexp.test(str)\n }))\n .map((chunk: ReadonlyChunk, index, chunks: readonly ReadonlyChunk[]) => ({\n // For each chunk, clip the text if needed\n ...chunk, // All the props first\n ...(typeof clipBy === 'number' && {\n // We only overwrite the text if there is a clip\n text: clip({\n curr: chunk, // We need the current chunk\n ...(index < chunks.length - 1 && { next: chunks[index + 1] }), // If this wasn't the last chunk, set the next chunk\n ...(index > 0 && { prev: chunks[index - 1] }), // If this wasn't the first chunk, set the previous chunk\n clipBy\n })\n })\n }));\n};\n\nexport default highlightWords;\n"],"names":[],"mappings":";;;;;;EAIA,IAAI,MAAM;EACV,IAAI,MAAM;EACV,OAAO;EACL,SAAO,IAAI,SAAS;EAAA;eAGM,MAAM;EAChC,MAAI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CAAC;EAAA,EACtB;EAAA,EACA;EAAA,EACA;EAAA,EACA,eAAe;EAAA;EAGf,QAAM,YAAY,MAAM;EAExB,MAAI,cAAc;EAChB,WAAO;EAAA,MACL;EAAA,QACE,KAAK;EAAA,QACL;EAAA,QACA,OAAO;EAAA;EAAA;EAAA;EAKb,QAAM,eAAe,IAAI,OACvB,YAAY,CAAE,OAAO,WAAW,gBAChC;EAKF,SAAO,KACJ,MAAM,cACN,OAAO,WACP,IAAI,CAAC;EAAS,IAEb,KAAK;EAAA,IACL,MAAM;EAAA,IACN,OAAO,eACH,IAAI,kBAAkB,UAAU,gBAChC,aAAa,KAAK;EAAA,MAEvB,IAAI,CAAC,OAAsB,OAAO,WAAsC,sBAEpE,QACC,OAAO,WAAW,YAAY;EAAA,IAEhC,MAAM,KAAK;EAAA,MACT,MAAM;EAAA,OACF,QAAQ,OAAO,SAAS,KAAK,CAAE,MAAM,OAAO,QAAQ,MACpD,QAAQ,KAAK,CAAE,MAAM,OAAO,QAAQ,MAH/B;EAAA,MAIT;EAAA;EAAA;EAAA;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"highlight-words.js","sources":["../../src/uid.ts","../../src/regexp.ts","../../src/clip.ts","../../src/index.ts"],"sourcesContent":["// https://github.com/lukeed/uid/blob/master/src/index.js\n/* eslint no-bitwise: 'off' */\n/* eslint no-plusplus: 'off' */\n/* eslint @typescript-eslint/strict-boolean-expressions: 'off' */\nlet IDX = 36;\nlet HEX = '';\nwhile (IDX--) {\n HEX += IDX.toString(36);\n}\n\nexport default function uid(len = 11): string {\n let str = '';\n let num = len;\n while (num--) {\n str += HEX[(Math.random() * 36) | 0];\n }\n return str;\n}\n","import type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\n// We need escape certain characters before creating the RegExp\n// https://github.com/sindresorhus/escape-string-regexp\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`);\n\nconst regexpQuery = ({\n terms,\n matchExactly = false\n}: Readonly<HighlightWords.Query>): string => {\n if (typeof terms !== 'string') {\n throw new TypeError('Expected a string');\n }\n\n const escapedTerms = escapeRegexp(terms.trim());\n return `(${matchExactly ? escapedTerms : escapedTerms.split(' ').join('|')})`;\n};\n\nexport default regexpQuery;\n","/* eslint complexity: [\"error\", { \"max\": 12 }] */\nimport type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\nconst hasProp = <T>(prop: string) => (obj: T) =>\n obj !== null && typeof obj !== 'undefined' && prop in obj;\nconst hasMatch = hasProp<HighlightWords.Chunk>('match');\n\nconst chunkExists = (\n chunk: HighlightWords.Chunk | undefined\n): chunk is HighlightWords.Chunk => typeof chunk !== 'undefined';\n\n/**\n * This provides context around a chunk's text, based on the next and previous chunks.\n * e.g. If we have the string \"The quick brown fox jumped over the lazy dog\",\n * and the search term \"fox jumped\", with a padding of 2, we want to have the end result be:\n * \"... quick brown fox jumped over the ...\"\n * The search term, \"fox jumped\" is left as is, and the left and right chunks, instead of having\n * the text in full, will be clipped.\n */\nexport default function clip({\n curr,\n next,\n prev,\n clipBy = 3\n}: HighlightWords.Clip): string {\n const words = curr.text.split(' ');\n const len = words.length;\n\n // If the current is a match, we leave it alone\n // Or if the clipBy is greater than or equal to the length of the words, there's nothing to clip\n if (curr.match || clipBy >= len) {\n return curr.text;\n }\n\n // If we have a clipBy greater than the length of the words in the current match,\n // it means we can clip the words in the current chunk\n const ellipsis = '...';\n\n if (\n chunkExists(next) &&\n chunkExists(prev) &&\n hasMatch(prev) &&\n hasMatch(next)\n ) {\n // Both the previous and the next chunks are a match\n // Let's check if we have enough words to clip by on both sides\n if (len > clipBy * 2) {\n return [\n ...words.slice(0, clipBy),\n ellipsis,\n ...words.slice(-clipBy)\n ].join(' ');\n }\n\n return curr.text;\n }\n\n // We start to check the next and previous matches in order to\n // properly position the elipsis\n if (chunkExists(next) && hasMatch(next)) {\n // The chunk right after this one is a match\n // So we need the elipsis at the start of the returned text\n // so that it sticks correctly to the next (match)'s text\n return [ellipsis, ...words.slice(-clipBy)].join(' ');\n }\n\n if (chunkExists(prev) && hasMatch(prev)) {\n // The chunk right before this one is a match\n // So we need the elipsis at the end of the returned text\n // so that it sticks correctly to the previous (match)'s text\n return [...words.slice(0, clipBy), ellipsis].join(' ');\n }\n\n // If we made it this far, just return the text\n return curr.text;\n}\n","import uid from './uid';\nimport regexpQuery from './regexp'; // eslint-disable-line import/no-cycle\nimport clip from './clip'; // eslint-disable-line import/no-cycle\n\n/* eslint-disable import/no-unused-modules */\ndeclare namespace HighlightWords {\n export interface Chunk {\n key: string;\n text: string;\n match: boolean;\n }\n\n export interface Options {\n text: string;\n query: string;\n clipBy?: number;\n matchExactly?: boolean;\n }\n\n export interface Clip {\n curr: Chunk;\n next?: Chunk;\n prev?: Chunk;\n clipBy?: number;\n }\n\n export interface Query {\n terms: string;\n matchExactly?: boolean;\n }\n}\n\nexport { HighlightWords };\n/* eslint-enable import/no-unused-modules */\n\nconst hasLength = (str: string): boolean => str.length > 0;\n\n/**\n * Split a text into chunks denoting which are a match and which are not based on a user search term.\n * @param text String The text to split.\n * @param query String The query to split by. This can contain multiple words.\n * @param clipBy Number Clip the non-matches by a certain number of words to provide context around the matches.\n * @param matchExactly Boolean If we have multiple words in the query, we will match any of the words if exact is false. For example, searching for \"brown fox\" in \"the brown cute fox\" will yield both \"brown\" and \"fox\" as matches. While if exact is true, the same search will return no results.\n */\nconst highlightWords = ({\n text,\n query,\n clipBy,\n matchExactly = false\n}: Readonly<HighlightWords.Options>): HighlightWords.Chunk[] => {\n // Let's make sure that the user cannot pass in just a bunch of spaces\n const safeQuery = query.trim();\n\n if (safeQuery === '') {\n return [\n {\n key: uid(),\n text,\n match: false\n }\n ];\n }\n\n const searchRegexp = new RegExp(\n regexpQuery({ terms: safeQuery, matchExactly }),\n 'ig'\n );\n\n type ReadonlyChunk = Readonly<HighlightWords.Chunk>; // eslint-disable-line @typescript-eslint/no-type-alias\n\n return text\n .split(searchRegexp) // Split the entire thing into an array of matches and non-matches\n .filter(hasLength) // Filter any matches that have the text with length of 0\n .map((str) => ({\n // Compose the object for a match\n key: uid(),\n text: str,\n match: matchExactly\n ? str.toLowerCase() === safeQuery.toLowerCase()\n : searchRegexp.test(str)\n }))\n .map((chunk: ReadonlyChunk, index, chunks: readonly ReadonlyChunk[]) => ({\n // For each chunk, clip the text if needed\n ...chunk, // All the props first\n ...(typeof clipBy === 'number' && {\n // We only overwrite the text if there is a clip\n text: clip({\n curr: chunk, // We need the current chunk\n ...(index < chunks.length - 1 && { next: chunks[index + 1] }), // If this wasn't the last chunk, set the next chunk\n ...(index > 0 && { prev: chunks[index - 1] }), // If this wasn't the first chunk, set the previous chunk\n clipBy\n })\n })\n }));\n};\n\nexport default highlightWords;\n"],"names":[],"mappings":";;;;AAIA,IAAI,MAAM;AACV,IAAI,MAAM;AACV,OAAO;AACL,SAAO,IAAI,SAAS;AAAA;aAGM,MAAM;AAChC,MAAI,MAAM;AACV,MAAI,MAAM;AACV,SAAO;AACL,WAAO,IAAK,KAAK,WAAW,KAAM;AAAA;AAEpC,SAAO;AAAA;;ACZT,MAAM,eAAe,CAAC,SACpB,KAAK,QAAQ,wBAAwB,CAAC,SAAiB,KAAK;AAE9D,MAAM,cAAc,CAAC;AAAA,EACnB;AAAA,EACA,eAAe;AAAA;AAEf,MAAI,OAAO,UAAU;AACnB,UAAM,IAAI,UAAU;AAAA;AAGtB,QAAM,eAAe,aAAa,MAAM;AACxC,SAAO,IAAI,eAAe,eAAe,aAAa,MAAM,KAAK,KAAK;AAAA;;ACbxE,MAAM,UAAU,CAAI,SAAiB,CAAC,QACpC,QAAQ,QAAQ,OAAO,QAAQ,eAAe,QAAQ;AACxD,MAAM,WAAW,QAA8B;AAE/C,MAAM,cAAc,CAClB,UACkC,OAAO,UAAU;cAUxB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA;AAET,QAAM,QAAQ,KAAK,KAAK,MAAM;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;AAAA,MAIT;AAAA;AAAA;AAAA;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"highlight-words.min.js","sources":["../../src/uid.ts","../../src/regexp.ts","../../src/clip.ts","../../src/index.ts"],"sourcesContent":["// https://github.com/lukeed/uid/blob/master/src/index.js\n/* eslint no-bitwise: 'off' */\n/* eslint no-plusplus: 'off' */\n/* eslint @typescript-eslint/strict-boolean-expressions: 'off' */\nlet IDX = 36;\nlet HEX = '';\nwhile (IDX--) {\n HEX += IDX.toString(36);\n}\n\nexport default function uid(len = 11): string {\n let str = '';\n let num = len;\n while (num--) {\n str += HEX[(Math.random() * 36) | 0];\n }\n return str;\n}\n","import type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\n// We need escape certain characters before creating the RegExp\n// https://github.com/sindresorhus/escape-string-regexp\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`);\n\nconst regexpQuery = ({\n terms,\n matchExactly = false\n}: Readonly<HighlightWords.Query>): string => {\n if (typeof terms !== 'string') {\n throw new TypeError('Expected a string');\n }\n\n const escapedTerms = escapeRegexp(terms.trim());\n return `(${matchExactly ? escapedTerms : escapedTerms.split(' ').join('|')})`;\n};\n\nexport default regexpQuery;\n","/* eslint complexity: [\"error\", { \"max\": 12 }] */\nimport type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\nconst hasProp = <T>(prop: string) => (obj: T) =>\n obj !== null && typeof obj !== 'undefined' && prop in obj;\nconst hasMatch = hasProp<HighlightWords.Chunk>('match');\n\nconst chunkExists = (\n chunk: HighlightWords.Chunk | undefined\n): chunk is HighlightWords.Chunk => typeof chunk !== 'undefined';\n\n/**\n * This provides context around a chunk's text, based on the next and previous chunks.\n * e.g. If we have the string \"The quick brown fox jumped over the lazy dog\",\n * and the search term \"fox jumped\", with a padding of 2, we want to have the end result be:\n * \"... quick brown fox jumped over the ...\"\n * The search term, \"fox jumped\" is left as is, and the left and right chunks, instead of having\n * the text in full, will be clipped.\n */\nexport default function clip({\n curr,\n next,\n prev,\n clipBy = 3\n}: HighlightWords.Clip): string {\n const words = curr.text.split(' ');\n const len = words.length;\n\n // If the current is a match, we leave it alone\n // Or if the clipBy is greater than or equal to the length of the words, there's nothing to clip\n if (curr.match || clipBy >= len) {\n return curr.text;\n }\n\n // If we have a clipBy greater than the length of the words in the current match,\n // it means we can clip the words in the current chunk\n const ellipsis = '...';\n\n if (\n chunkExists(next) &&\n chunkExists(prev) &&\n hasMatch(prev) &&\n hasMatch(next)\n ) {\n // Both the previous and the next chunks are a match\n // Let's check if we have enough words to clip by on both sides\n if (len > clipBy * 2) {\n return [\n ...words.slice(0, clipBy),\n ellipsis,\n ...words.slice(-clipBy)\n ].join(' ');\n }\n\n return curr.text;\n }\n\n // We start to check the next and previous matches in order to\n // properly position the elipsis\n if (chunkExists(next) && hasMatch(next)) {\n // The chunk right after this one is a match\n // So we need the elipsis at the start of the returned text\n // so that it sticks correctly to the next (match)'s text\n return [ellipsis, ...words.slice(-clipBy)].join(' ');\n }\n\n if (chunkExists(prev) && hasMatch(prev)) {\n // The chunk right before this one is a match\n // So we need the elipsis at the end of the returned text\n // so that it sticks correctly to the previous (match)'s text\n return [...words.slice(0, clipBy), ellipsis].join(' ');\n }\n\n // If we made it this far, just return the text\n return curr.text;\n}\n","import uid from './uid';\nimport regexpQuery from './regexp'; // eslint-disable-line import/no-cycle\nimport clip from './clip'; // eslint-disable-line import/no-cycle\n\n/* eslint-disable import/no-unused-modules */\ndeclare namespace HighlightWords {\n export interface Chunk {\n key: string;\n text: string;\n match: boolean;\n }\n\n export interface Options {\n text: string;\n query: string;\n clipBy?: number;\n matchExactly?: boolean;\n }\n\n export interface Clip {\n curr: Chunk;\n next?: Chunk;\n prev?: Chunk;\n clipBy?: number;\n }\n\n export interface Query {\n terms: string;\n matchExactly?: boolean;\n }\n}\n\nexport { HighlightWords };\n/* eslint-enable import/no-unused-modules */\n\nconst hasLength = (str: string): boolean => str.length > 0;\n\n/**\n * Split a text into chunks denoting which are a match and which are not based on a user search term.\n * @param text String The text to split.\n * @param query String The query to split by. This can contain multiple words.\n * @param clipBy Number Clip the non-matches by a certain number of words to provide context around the matches.\n * @param matchExactly Boolean If we have multiple words in the query, we will match any of the words if exact is false. For example, searching for \"brown fox\" in \"the brown cute fox\" will yield both \"brown\" and \"fox\" as matches. While if exact is true, the same search will return no results.\n */\nconst highlightWords = ({\n text,\n query,\n clipBy,\n matchExactly = false\n}: Readonly<HighlightWords.Options>): HighlightWords.Chunk[] => {\n // Let's make sure that the user cannot pass in just a bunch of spaces\n const safeQuery = query.trim();\n\n if (safeQuery === '') {\n return [\n {\n key: uid(),\n text,\n match: false\n }\n ];\n }\n\n const searchRegexp = new RegExp(\n regexpQuery({ terms: safeQuery, matchExactly }),\n 'ig'\n );\n\n type ReadonlyChunk = Readonly<HighlightWords.Chunk>; // eslint-disable-line @typescript-eslint/no-type-alias\n\n return text\n .split(searchRegexp) // Split the entire thing into an array of matches and non-matches\n .filter(hasLength) // Filter any matches that have the text with length of 0\n .map((str) => ({\n // Compose the object for a match\n key: uid(),\n text: str,\n match: matchExactly\n ? str.toLowerCase() === safeQuery.toLowerCase()\n : searchRegexp.test(str)\n }))\n .map((chunk: ReadonlyChunk, index, chunks: readonly ReadonlyChunk[]) => ({\n // For each chunk, clip the text if needed\n ...chunk, // All the props first\n ...(typeof clipBy === 'number' && {\n // We only overwrite the text if there is a clip\n text: clip({\n curr: chunk, // We need the current chunk\n ...(index < chunks.length - 1 && { next: chunks[index + 1] }), // If this wasn't the last chunk, set the next chunk\n ...(index > 0 && { prev: chunks[index - 1] }), // If this wasn't the first chunk, set the previous chunk\n clipBy\n })\n })\n }));\n};\n\nexport default highlightWords;\n"],"names":[],"mappings":";;;;AAIA,IAAI,MAAM;AACV,IAAI,MAAM;AACV,OAAO;AACL,SAAO,IAAI,SAAS;AAAA;aAGM,MAAM;AAChC,MAAI,MAAM;AACV,MAAI,MAAM;AACV,S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AA,EACA;AAAA,EACA,eAAe;AAAA;AAGf,QAAM,YAAY,MAAM;AAExB,MAAI,cAAc;AAChB,WAAO;AAAA,MACL;AAAA,QACE,KAAK;AAAA,QACL;AAAA,QACA,OAAO;AAAA;AAAA;AAAA;AAKb,QAAM,eAAe,IAAI,OACvB,YAAY,CAAE,OAAO,WAAW,gBAChC;AAKF,SAAO,KACJ,MAAM,cACN,OAAO,WACP,IAAI,CAAC;AAAS,IAEb,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO,eACH,IAAI,kBAAkB,UAAU,gBAChC,aAAa,KAAK;AAAA,MAEvB,IAAI,CAAC,OAAsB,OAAO,WAAsC,sBAEpE,QACC,OAAO,WAAW,YAAY;AAAA,IAEhC,MAAM,KAAK;AAAA,MACT,MAAM;AAAA,OACF,QAAQ,OAAO,SAAS,KAAK,CAAE,MAAM,OAAO,QAAQ,MACpD,QAAQ,KAAK,CAAE,MAAM,OAAO,QAAQ,MAH/B;AAAA,MAIT;AAAA;AAAA;AAAA;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"highlight-words.js","sources":["../../src/uid.ts","../../src/regexp.ts","../../src/clip.ts","../../src/index.ts"],"sourcesContent":["// https://github.com/lukeed/uid/blob/master/src/index.js\n/* eslint no-bitwise: 'off' */\n/* eslint no-plusplus: 'off' */\n/* eslint @typescript-eslint/strict-boolean-expressions: 'off' */\nlet IDX = 36;\nlet HEX = '';\nwhile (IDX--) {\n HEX += IDX.toString(36);\n}\n\nexport default function uid(len = 11): string {\n let str = '';\n let num = len;\n while (num--) {\n str += HEX[(Math.random() * 36) | 0];\n }\n return str;\n}\n","import type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\n// We need escape certain characters before creating the RegExp\n// https://github.com/sindresorhus/escape-string-regexp\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`);\n\nconst regexpQuery = ({\n terms,\n matchExactly = false\n}: Readonly<HighlightWords.Query>): string => {\n if (typeof terms !== 'string') {\n throw new TypeError('Expected a string');\n }\n\n const escapedTerms = escapeRegexp(terms.trim());\n return `(${matchExactly ? escapedTerms : escapedTerms.split(' ').join('|')})`;\n};\n\nexport default regexpQuery;\n","/* eslint complexity: [\"error\", { \"max\": 12 }] */\nimport type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\nconst hasProp = <T>(prop: string) => (obj: T) =>\n obj !== null && typeof obj !== 'undefined' && prop in obj;\nconst hasMatch = hasProp<HighlightWords.Chunk>('match');\n\nconst chunkExists = (\n chunk: HighlightWords.Chunk | undefined\n): chunk is HighlightWords.Chunk => typeof chunk !== 'undefined';\n\n/**\n * This provides context around a chunk's text, based on the next and previous chunks.\n * e.g. If we have the string \"The quick brown fox jumped over the lazy dog\",\n * and the search term \"fox jumped\", with a padding of 2, we want to have the end result be:\n * \"... quick brown fox jumped over the ...\"\n * The search term, \"fox jumped\" is left as is, and the left and right chunks, instead of having\n * the text in full, will be clipped.\n */\nexport default function clip({\n curr,\n next,\n prev,\n clipBy = 3\n}: HighlightWords.Clip): string {\n const words = curr.text.split(' ');\n const len = words.length;\n\n // If the current is a match, we leave it alone\n // Or if the clipBy is greater than or equal to the length of the words, there's nothing to clip\n if (curr.match || clipBy >= len) {\n return curr.text;\n }\n\n // If we have a clipBy greater than the length of the words in the current match,\n // it means we can clip the words in the current chunk\n const ellipsis = '...';\n\n if (\n chunkExists(next) &&\n chunkExists(prev) &&\n hasMatch(prev) &&\n hasMatch(next)\n ) {\n // Both the previous and the next chunks are a match\n // Let's check if we have enough words to clip by on both sides\n if (len > clipBy * 2) {\n return [\n ...words.slice(0, clipBy),\n ellipsis,\n ...words.slice(-clipBy)\n ].join(' ');\n }\n\n return curr.text;\n }\n\n // We start to check the next and previous matches in order to\n // properly position the elipsis\n if (chunkExists(next) && hasMatch(next)) {\n // The chunk right after this one is a match\n // So we need the elipsis at the start of the returned text\n // so that it sticks correctly to the next (match)'s text\n return [ellipsis, ...words.slice(-clipBy)].join(' ');\n }\n\n if (chunkExists(prev) && hasMatch(prev)) {\n // The chunk right before this one is a match\n // So we need the elipsis at the end of the returned text\n // so that it sticks correctly to the previous (match)'s text\n return [...words.slice(0, clipBy), ellipsis].join(' ');\n }\n\n // If we made it this far, just return the text\n return curr.text;\n}\n","import uid from './uid';\nimport regexpQuery from './regexp'; // eslint-disable-line import/no-cycle\nimport clip from './clip'; // eslint-disable-line import/no-cycle\n\n/* eslint-disable import/no-unused-modules */\ndeclare namespace HighlightWords {\n export interface Chunk {\n key: string;\n text: string;\n match: boolean;\n }\n\n export interface Options {\n text: string;\n query: string;\n clipBy?: number;\n matchExactly?: boolean;\n }\n\n export interface Clip {\n curr: Chunk;\n next?: Chunk;\n prev?: Chunk;\n clipBy?: number;\n }\n\n export interface Query {\n terms: string;\n matchExactly?: boolean;\n }\n}\n\nexport { HighlightWords };\n/* eslint-enable import/no-unused-modules */\n\nconst hasLength = (str: string): boolean => str.length > 0;\n\n/**\n * Split a text into chunks denoting which are a match and which are not based on a user search term.\n * @param text String The text to split.\n * @param query String The query to split by. This can contain multiple words.\n * @param clipBy Number Clip the non-matches by a certain number of words to provide context around the matches.\n * @param matchExactly Boolean If we have multiple words in the query, we will match any of the words if exact is false. For example, searching for \"brown fox\" in \"the brown cute fox\" will yield both \"brown\" and \"fox\" as matches. While if exact is true, the same search will return no results.\n */\nconst highlightWords = ({\n text,\n query,\n clipBy,\n matchExactly = false\n}: Readonly<HighlightWords.Options>): HighlightWords.Chunk[] => {\n // Let's make sure that the user cannot pass in just a bunch of spaces\n const safeQuery = query.trim();\n\n if (safeQuery === '') {\n return [\n {\n key: uid(),\n text,\n match: false\n }\n ];\n }\n\n const searchRegexp = new RegExp(\n regexpQuery({ terms: safeQuery, matchExactly }),\n 'ig'\n );\n\n type ReadonlyChunk = Readonly<HighlightWords.Chunk>; // eslint-disable-line @typescript-eslint/no-type-alias\n\n return text\n .split(searchRegexp) // Split the entire thing into an array of matches and non-matches\n .filter(hasLength) // Filter any matches that have the text with length of 0\n .map((str) => ({\n // Compose the object for a match\n key: uid(),\n text: str,\n match: matchExactly\n ? str.toLowerCase() === safeQuery.toLowerCase()\n : searchRegexp.test(str)\n }))\n .map((chunk: ReadonlyChunk, index, chunks: readonly ReadonlyChunk[]) => ({\n // For each chunk, clip the text if needed\n ...chunk, // All the props first\n ...(typeof clipBy === 'number' && {\n // We only overwrite the text if there is a clip\n text: clip({\n curr: chunk, // We need the current chunk\n ...(index < chunks.length - 1 && { next: chunks[index + 1] }), // If this wasn't the last chunk, set the next chunk\n ...(index > 0 && { prev: chunks[index - 1] }), // If this wasn't the first chunk, set the previous chunk\n clipBy\n })\n })\n }));\n};\n\nexport default highlightWords;\n"],"names":[],"mappings":"AAIA,IAAI,MAAM;AACV,IAAI,MAAM;AACV,OAAO;AACL,SAAO,IAAI,SAAS;AAAA;aAGM,MAAM;AAChC,MAAI,MAAM;AACV,MAAI,MAAM;AACV,SAAO;AACL,WAAO,IAAK,KAAK,WAAW,KAAM;AAAA;AAEpC,SAAO;AAAA;;ACZT,MAAM,eAAe,CAAC,SACpB,KAAK,QAAQ,wBAAwB,CAAC,SAAiB,KAAK;AAE9D,MAAM,cAAc,CAAC;AAAA,EACnB;AAAA,EACA,eAAe;AAAA;AAEf,MAAI,OAAO,UAAU;AACnB,UAAM,IAAI,UAAU;AAAA;AAGtB,QAAM,eAAe,aAAa,MAAM;AACxC,SAAO,IAAI,eAAe,eAAe,aAAa,MAAM,KAAK,KAAK;AAAA;;ACbxE,MAAM,UAAU,CAAI,SAAiB,CAAC,QACpC,QAAQ,QAAQ,OAAO,QAAQ,eAAe,QAAQ;AACxD,MAAM,WAAW,QAA8B;AAE/C,MAAM,cAAc,CAClB,UACkC,OAAO,UAAU;cAUxB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA;AAET,QAAM,QAAQ,KAAK,KAAK,MAAM;AAC9B,QAAM,MAAM,MAAM;AAIlB,MAAI,K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@ -1 +0,0 @@
1
- {"version":3,"file":"highlight-words.min.js","sources":["../../src/uid.ts","../../src/regexp.ts","../../src/clip.ts","../../src/index.ts"],"sourcesContent":["// https://github.com/lukeed/uid/blob/master/src/index.js\n/* eslint no-bitwise: 'off' */\n/* eslint no-plusplus: 'off' */\n/* eslint @typescript-eslint/strict-boolean-expressions: 'off' */\nlet IDX = 36;\nlet HEX = '';\nwhile (IDX--) {\n HEX += IDX.toString(36);\n}\n\nexport default function uid(len = 11): string {\n let str = '';\n let num = len;\n while (num--) {\n str += HEX[(Math.random() * 36) | 0];\n }\n return str;\n}\n","import type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\n// We need escape certain characters before creating the RegExp\n// https://github.com/sindresorhus/escape-string-regexp\nconst escapeRegexp = (term: string): string =>\n term.replace(/[|\\\\{}()[\\]^$+*?.-]/g, (char: string) => `\\\\${char}`);\n\nconst regexpQuery = ({\n terms,\n matchExactly = false\n}: Readonly<HighlightWords.Query>): string => {\n if (typeof terms !== 'string') {\n throw new TypeError('Expected a string');\n }\n\n const escapedTerms = escapeRegexp(terms.trim());\n return `(${matchExactly ? escapedTerms : escapedTerms.split(' ').join('|')})`;\n};\n\nexport default regexpQuery;\n","/* eslint complexity: [\"error\", { \"max\": 12 }] */\nimport type { HighlightWords } from '.'; // eslint-disable-line import/no-cycle\n\nconst hasProp = <T>(prop: string) => (obj: T) =>\n obj !== null && typeof obj !== 'undefined' && prop in obj;\nconst hasMatch = hasProp<HighlightWords.Chunk>('match');\n\nconst chunkExists = (\n chunk: HighlightWords.Chunk | undefined\n): chunk is HighlightWords.Chunk => typeof chunk !== 'undefined';\n\n/**\n * This provides context around a chunk's text, based on the next and previous chunks.\n * e.g. If we have the string \"The quick brown fox jumped over the lazy dog\",\n * and the search term \"fox jumped\", with a padding of 2, we want to have the end result be:\n * \"... quick brown fox jumped over the ...\"\n * The search term, \"fox jumped\" is left as is, and the left and right chunks, instead of having\n * the text in full, will be clipped.\n */\nexport default function clip({\n curr,\n next,\n prev,\n clipBy = 3\n}: HighlightWords.Clip): string {\n const words = curr.text.split(' ');\n const len = words.length;\n\n // If the current is a match, we leave it alone\n // Or if the clipBy is greater than or equal to the length of the words, there's nothing to clip\n if (curr.match || clipBy >= len) {\n return curr.text;\n }\n\n // If we have a clipBy greater than the length of the words in the current match,\n // it means we can clip the words in the current chunk\n const ellipsis = '...';\n\n if (\n chunkExists(next) &&\n chunkExists(prev) &&\n hasMatch(prev) &&\n hasMatch(next)\n ) {\n // Both the previous and the next chunks are a match\n // Let's check if we have enough words to clip by on both sides\n if (len > clipBy * 2) {\n return [\n ...words.slice(0, clipBy),\n ellipsis,\n ...words.slice(-clipBy)\n ].join(' ');\n }\n\n return curr.text;\n }\n\n // We start to check the next and previous matches in order to\n // properly position the elipsis\n if (chunkExists(next) && hasMatch(next)) {\n // The chunk right after this one is a match\n // So we need the elipsis at the start of the returned text\n // so that it sticks correctly to the next (match)'s text\n return [ellipsis, ...words.slice(-clipBy)].join(' ');\n }\n\n if (chunkExists(prev) && hasMatch(prev)) {\n // The chunk right before this one is a match\n // So we need the elipsis at the end of the returned text\n // so that it sticks correctly to the previous (match)'s text\n return [...words.slice(0, clipBy), ellipsis].join(' ');\n }\n\n // If we made it this far, just return the text\n return curr.text;\n}\n","import uid from './uid';\nimport regexpQuery from './regexp'; // eslint-disable-line import/no-cycle\nimport clip from './clip'; // eslint-disable-line import/no-cycle\n\n/* eslint-disable import/no-unused-modules */\ndeclare namespace HighlightWords {\n export interface Chunk {\n key: string;\n text: string;\n match: boolean;\n }\n\n export interface Options {\n text: string;\n query: string;\n clipBy?: number;\n matchExactly?: boolean;\n }\n\n export interface Clip {\n curr: Chunk;\n next?: Chunk;\n prev?: Chunk;\n clipBy?: number;\n }\n\n export interface Query {\n terms: string;\n matchExactly?: boolean;\n }\n}\n\nexport { HighlightWords };\n/* eslint-enable import/no-unused-modules */\n\nconst hasLength = (str: string): boolean => str.length > 0;\n\n/**\n * Split a text into chunks denoting which are a match and which are not based on a user search term.\n * @param text String The text to split.\n * @param query String The query to split by. This can contain multiple words.\n * @param clipBy Number Clip the non-matches by a certain number of words to provide context around the matches.\n * @param matchExactly Boolean If we have multiple words in the query, we will match any of the words if exact is false. For example, searching for \"brown fox\" in \"the brown cute fox\" will yield both \"brown\" and \"fox\" as matches. While if exact is true, the same search will return no results.\n */\nconst highlightWords = ({\n text,\n query,\n clipBy,\n matchExactly = false\n}: Readonly<HighlightWords.Options>): HighlightWords.Chunk[] => {\n // Let's make sure that the user cannot pass in just a bunch of spaces\n const safeQuery = query.trim();\n\n if (safeQuery === '') {\n return [\n {\n key: uid(),\n text,\n match: false\n }\n ];\n }\n\n const searchRegexp = new RegExp(\n regexpQuery({ terms: safeQuery, matchExactly }),\n 'ig'\n );\n\n type ReadonlyChunk = Readonly<HighlightWords.Chunk>; // eslint-disable-line @typescript-eslint/no-type-alias\n\n return text\n .split(searchRegexp) // Split the entire thing into an array of matches and non-matches\n .filter(hasLength) // Filter any matches that have the text with length of 0\n .map((str) => ({\n // Compose the object for a match\n key: uid(),\n text: str,\n match: matchExactly\n ? str.toLowerCase() === safeQuery.toLowerCase()\n : searchRegexp.test(str)\n }))\n .map((chunk: ReadonlyChunk, index, chunks: readonly ReadonlyChunk[]) => ({\n // For each chunk, clip the text if needed\n ...chunk, // All the props first\n ...(typeof clipBy === 'number' && {\n // We only overwrite the text if there is a clip\n text: clip({\n curr: chunk, // We need the current chunk\n ...(index < chunks.length - 1 && { next: chunks[index + 1] }), // If this wasn't the last chunk, set the next chunk\n ...(index > 0 && { prev: chunks[index - 1] }), // If this wasn't the first chunk, set the previous chunk\n clipBy\n })\n })\n }));\n};\n\nexport default highlightWords;\n"],"names":[],"mappings":"AAIA,IAAI,MAAM;AACV,IAAI,MAAM;AACV,OAAO;AACL,SAAO,IAAI,SAAS;AAAA;aAGM,MAAM;AAChC,MAAI,MAAM;AACV,MAAI,MAAM;AACV,SAAO;AACL,WAAO,IAAK,KAAK,WAAW,KAAM;AAA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