Skip to content

Commit f585811

Browse files
committed
added initial version
1 parent 05777d7 commit f585811

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ node_modules
3131

3232
# Optional REPL history
3333
.node_repl_history
34+
35+
lib/

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016
3+
Copyright (c) 2016 Nikolaus Graf
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# findWithRegex Util
2+
3+
## License
4+
5+
MIT

package.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "find-with-regex",
3+
"version": "1.0.0",
4+
"description": "findWithRegex util",
5+
"author": {
6+
"name": "Nik Graf",
7+
"email": "nik@nikgraf.com",
8+
"url": "http://www.nikgraf.com"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git@github.com:draft-js-plugins/find-with-regex.git"
13+
},
14+
"main": "lib/index.js",
15+
"keywords": [],
16+
"scripts": {
17+
"build": "BABEL_ENV=production babel --out-dir='lib' --ignore='__tests__/*' src",
18+
"lint": "npm run lint:eslint && npm run lint:jscs",
19+
"lint:eslint": "eslint --rule 'mocha/no-exclusive-tests:2' ./",
20+
"lint:eslint:fix": "eslint --fix --rule 'mocha/no-exclusive-tests:2' ./",
21+
"lint:jscs": "jscs ./",
22+
"prepublish": "npm run build",
23+
},
24+
"devDependencies": {
25+
"babel": "^6.5.1",
26+
"babel-cli": "^6.5.1",
27+
"babel-core": "^6.5.1",
28+
"babel-eslint": "^4.1.8",
29+
"babel-preset-es2015": "^6.5.0",
30+
"babel-preset-stage-0": "^6.5.0",
31+
"eslint": "^1.10.3",
32+
"eslint-config-airbnb": "5.0.0",
33+
"eslint-plugin-mocha": "^1.1.0",
34+
"eslint-plugin-react": "^3.16.1"
35+
},
36+
"license": "MIT"
37+
}

src/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const findWithRegex = (regex, contentBlock, callback) => {
2+
// Get the text from the contentBlock
3+
const text = contentBlock.getText();
4+
let matchArr;
5+
let start; // eslint-disable-line
6+
// Go through all matches in the text and return the indizes to the callback
7+
while ((matchArr = regex.exec(text)) !== null) { // eslint-disable-line
8+
start = matchArr.index;
9+
callback(start, start + matchArr[0].length);
10+
}
11+
};
12+
13+
export default findWithRegex;

0 commit comments

Comments
 (0)