Skip to content

Commit

Permalink
using native matchAll string function
Browse files Browse the repository at this point in the history
  • Loading branch information
Alognas2 authored and riccardoferretti committed Nov 25, 2020
1 parent 9c7e6b0 commit 7bfed3f
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 11 deletions.
2 changes: 0 additions & 2 deletions packages/foam-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@types/lodash": "^4.14.157",
"@types/micromatch": "^4.0.1",
"@types/picomatch": "^2.2.1",
"@types/string.prototype.matchall": "^4.0.0",
"husky": "^4.2.5",
"tsdx": "^0.13.2",
"tslib": "^2.0.0",
Expand All @@ -37,7 +36,6 @@
"remark-frontmatter": "^2.0.0",
"remark-parse": "^8.0.2",
"remark-wiki-link": "^0.0.4",
"string.prototype.matchall": "^4.0.2",
"title-case": "^3.0.2",
"unified": "^9.0.0",
"unist-util-visit": "^2.0.2",
Expand Down
5 changes: 2 additions & 3 deletions packages/foam-core/src/utils/hashtags.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { isSome, isNumeric } from './core';
import matchAll from 'string.prototype.matchall';

const HASHTAG_REGEX = /(^|[ ])#([\w_-]+\b)/gm;
const WORD_REGEX = /(^|[ ])([\w_-]+\b)/gm;

export const extractHashtags = (text: string): Set<string> => {
return isSome(text)
? new Set(
Array.from(matchAll(text, HASHTAG_REGEX))
Array.from([...text.matchAll(HASHTAG_REGEX)])
.map(m => m[2].trim())
.filter(tag => !isNumeric(tag))
)
Expand All @@ -17,6 +16,6 @@ export const extractHashtags = (text: string): Set<string> => {
export const extractTagsFromProp = (prop: string | string[]): Set<string> => {
const text = Array.isArray(prop) ? prop.join(' ') : prop;
return isSome(text)
? new Set(Array.from(matchAll(text, WORD_REGEX)).map(m => m[2].trim()))
? new Set(Array.from(text.matchAll(WORD_REGEX)).map(m => m[2].trim()))
: new Set();
};
2 changes: 1 addition & 1 deletion packages/foam-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"sourceMap": true,
"strict": true,
"lib": [
"ES2019"
"ES2019", "es2020.string"
]
},
"include": [
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2842,11 +2842,6 @@
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
integrity sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==

"@types/string.prototype.matchall@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/string.prototype.matchall/-/string.prototype.matchall-4.0.0.tgz#cd00ed3b223d02c8bf978d2866f54fd0e68026cd"
integrity sha512-PAspRKHfv4D2TDX4PPHzJ/IxI29ahUyQsTIyFl2/keG+C+mk0Gx3ksYNYRC1AWMmtbbjDeC/LTKOtkEB3ETJOA==

"@types/unist@^2.0.0", "@types/unist@^2.0.2":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
Expand Down

0 comments on commit 7bfed3f

Please sign in to comment.