-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from rpearce/ts
convert to typescript
- Loading branch information
Showing
19 changed files
with
4,039 additions
and
2,601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
!.eslintrc.js | ||
!.prettierrc.js | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,4 +60,6 @@ typings/ | |
# next.js build output | ||
.next | ||
|
||
dist/ | ||
*.tmp | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
language: node_js | ||
node_js: | ||
- "12" | ||
- "13" | ||
before_install: | ||
- curl -o- -L https://yarnpkg.com/install.sh | bash | ||
- export PATH="$HOME/.yarn/bin:$PATH" | ||
cache: yarn | ||
script: | ||
- yarn ci | ||
after_success: | ||
- npm run coverage | ||
- yarn run coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
ISC License (ISC) | ||
Copyright (c) 2020, Robert Pearce | ||
|
||
Copyright 2019 Robert Pearce | ||
All rights reserved. | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* Neither the name of Robert Pearce nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React from 'react' | ||
import flexibleStringReplace from '../source' | ||
|
||
test('flexibleStringReplace is defined', () => { | ||
expect(flexibleStringReplace).toBeDefined() | ||
}) | ||
|
||
test('string pattern & string replacer for first match', () => { | ||
const str = 'The rain in Spain falls mainly on the plain. Spain is nice.' | ||
const pattern = 'Spain' | ||
const replacer = 'foo bar baz' | ||
const res = flexibleStringReplace(pattern, replacer, str) | ||
|
||
expect(res).toEqual([ | ||
'The rain in ', | ||
'foo bar baz', | ||
' falls mainly on the plain. Spain is nice.' | ||
]) | ||
}) | ||
|
||
test('string pattern & html interpolation for first match', () => { | ||
const str = 'The rain in Spain falls mainly on the plain. Spain is nice.' | ||
const pattern = 'Spain' | ||
const replacer = (match: string): string => `<mark>${match}</mark>` | ||
const res = flexibleStringReplace(pattern, replacer, str) | ||
|
||
expect(res).toEqual([ | ||
'The rain in ', | ||
'<mark>Spain</mark>', | ||
' falls mainly on the plain. Spain is nice.' | ||
]) | ||
}) | ||
|
||
test('regexp pattern & html string interpolation function with matches', () => { | ||
const str = 'The rain in Spain falls mainly on the plain. Spain is nice.' | ||
const pattern = new RegExp('Spain', 'igm') | ||
const replacer = (match: string): string => `<mark>${match}</mark>` | ||
const res = flexibleStringReplace(pattern, replacer, str) | ||
|
||
expect(res).toEqual([ | ||
'The rain in ', | ||
'<mark>Spain</mark>', | ||
' falls mainly on the plain. ', | ||
'<mark>Spain</mark>', | ||
' is nice.' | ||
]) | ||
}) | ||
|
||
test('forwards matching group parts in replacer params', () => { | ||
const str = 'Dear @diary, I hope this test #passes #pray' | ||
const pattern = /\s(@\w+)|\s(#\w+)/gm | ||
const ats: string[] = [] | ||
const tags: string[] = [] | ||
const replacer = (match: string, at: string, tag: string): void => { | ||
if (at) { | ||
ats.push(at) | ||
} | ||
if (tag) { | ||
tags.push(tag) | ||
} | ||
} | ||
flexibleStringReplace(pattern, replacer, str) | ||
|
||
expect(ats).toEqual(['@diary']) | ||
expect(tags).toEqual(['#passes', '#pray']) | ||
}) | ||
|
||
test('regexp pattern & react interpolation function', () => { | ||
const str = 'The rain in Spain falls mainly on the plain. Spain is nice.' | ||
const pattern = new RegExp('Spain', 'igm') | ||
const replacer = (match: string, offset: string): JSX.Element => ( | ||
<mark key={offset}>{match}</mark> | ||
) | ||
const res = flexibleStringReplace(pattern, replacer, str) | ||
|
||
expect(res).toEqual([ | ||
'The rain in ', | ||
<mark key={12}>Spain</mark>, | ||
' falls mainly on the plain. ', | ||
<mark key={45}>Spain</mark>, | ||
' is nice.' | ||
]) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
clearMocks: true, | ||
collectCoverage: true, | ||
collectCoverageFrom: ['<rootDir>/source/**/*.{ts,tsx}'], | ||
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/source/@types'], | ||
moduleNameMapper: {}, | ||
preset: 'ts-jest', | ||
setupFilesAfterEnv: [], | ||
verbose: true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
'*.js': ['eslint --fix', 'git add'] | ||
'*.{js,ts,tsx}': ['eslint --fix'] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.