Skip to content

Commit

Permalink
postings in one line
Browse files Browse the repository at this point in the history
  • Loading branch information
sadasant committed Mar 24, 2017
1 parent 663b90d commit 86a3923
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ export const deepMap = _.curry((fn, obj, _map = map, is = isTraversable) =>
// Misc
// ----
export const testRegex = regex => regex.test.bind(regex)

// Gets all the regexp.exec indexes and their respective lastIndexes
export const postings = _.curry((r, s) =>
_.map(x => (m => [m.index, r.lastIndex])(r.exec(s)), s.match(r)))
4 changes: 4 additions & 0 deletions test/misc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ describe('Regexp Functions', () => {
expect(f.testRegex(/smart/i)('SmartProcure')).to.equal(true)
expect(f.testRegex(/smart/)('SmartProcure')).to.equal(false)
})
it('postings', () => {
expect(f.postings(/p/gi, 'pretty please')).to.deep.equal([[0, 1], [7, 8]])
expect(f.postings(/wh/gi, 'what whale')).to.deep.equal([[0, 2], [5, 7]])
})
})

0 comments on commit 86a3923

Please sign in to comment.