Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
591 additions
and
802 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
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,5 @@ | ||
export default function bindNot(fn) { | ||
return function () { | ||
return !fn.apply(this, arguments); | ||
}; | ||
} |
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,37 @@ | ||
import bindNot from '.'; | ||
|
||
describe('bindNot', () => { | ||
it('Should return return a function', () => { | ||
expect(typeof bindNot(jest.fn())).toBe('function'); | ||
}); | ||
|
||
test('calling returned function runs accepted function', () => { | ||
const fn = jest.fn(); | ||
|
||
expect(fn).not.toHaveBeenCalled(); | ||
const not = bindNot(fn); | ||
expect(fn).not.toHaveBeenCalled(); | ||
not(); | ||
expect(fn).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('Should pass arguments to accepted function', () => { | ||
const fn = jest.fn(); | ||
|
||
const not = bindNot(fn); | ||
not(1, 2, 3, 4); | ||
expect(fn).toHaveBeenCalledWith(1, 2, 3, 4); | ||
}); | ||
|
||
it('Should return the boolean negation of the original function', () => { | ||
expect(bindNot(() => true)()).toBe(false); | ||
expect(bindNot(() => false)()).toBe(true); | ||
expect(bindNot(() => 'string')()).toBe(false); | ||
expect(bindNot(() => [])()).toBe(false); | ||
expect(bindNot(() => '')()).toBe(true); | ||
expect(bindNot(() => 0)()).toBe(true); | ||
expect(bindNot(() => NaN)()).toBe(true); | ||
expect(bindNot(() => null)()).toBe(true); | ||
expect(bindNot(() => undefined)()).toBe(true); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { default as extendRules } from './extendRules'; | ||
export { default as isRule } from './isRule'; | ||
export { default as proxySupported } from './proxySupported'; | ||
export { default as throwError } from './throwError'; | ||
export { default as bindNot } from './bindNot'; |
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,11 @@ | ||
function endsWith(value, arg1) { | ||
return typeof value === 'string' && typeof arg1 === 'string' && value.endsWith(arg1); | ||
} | ||
import { bindNot } from '../../lib'; | ||
|
||
endsWith.negativeForm = 'doesNotEndWith'; | ||
export function endsWith(value, arg1) { | ||
return ( | ||
typeof value === 'string' && | ||
typeof arg1 === 'string' && | ||
value.endsWith(arg1) | ||
); | ||
} | ||
|
||
export default endsWith; | ||
export const doesNotEndWith = bindNot(endsWith); |
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,33 +1,31 @@ | ||
import endsWith from '.'; | ||
import { endsWith } from '.'; | ||
|
||
describe('Tests isArray rule', () => { | ||
const word = 'meow'; | ||
const totallyDifferentWord = 'lorem'; | ||
it('Should return true for the same word', () => { | ||
expect(endsWith(word, word)).toBe(true); | ||
}); | ||
const word = 'meow'; | ||
const totallyDifferentWord = 'lorem'; | ||
it('Should return true for the same word', () => { | ||
expect(endsWith(word, word)).toBe(true); | ||
}); | ||
|
||
it('Should return true for a suffix', () => { | ||
expect(endsWith(word, word.substring(word.length / 2, word.length))).toBe(true); | ||
}); | ||
it('Should return true for a suffix', () => { | ||
expect(endsWith(word, word.substring(word.length / 2, word.length))).toBe( | ||
true | ||
); | ||
}); | ||
|
||
it('Should return true for empty suffix', () => { | ||
expect(endsWith(word, '')).toBe(true); | ||
}); | ||
it('Should return true for empty suffix', () => { | ||
expect(endsWith(word, '')).toBe(true); | ||
}); | ||
|
||
it('Should return false for a wrong suffix', () => { | ||
expect(endsWith(word, word.substring(0, word.length - 1))).toBe(false); | ||
}); | ||
it('Should return false for a wrong suffix', () => { | ||
expect(endsWith(word, word.substring(0, word.length - 1))).toBe(false); | ||
}); | ||
|
||
it('Should return false for a suffix which is a totally different word', () => { | ||
expect(endsWith(word, totallyDifferentWord)).toBe(false); | ||
}); | ||
it('Should return false for a suffix which is a totally different word', () => { | ||
expect(endsWith(word, totallyDifferentWord)).toBe(false); | ||
}); | ||
|
||
it('Should return false for a suffix longer than the word', () => { | ||
expect(endsWith(word, word.repeat(2))).toBe(false); | ||
}); | ||
|
||
it('Should expose negativeForm property', () => { | ||
expect(endsWith.negativeForm).toBe('doesNotEndWith'); | ||
}); | ||
it('Should return false for a suffix longer than the word', () => { | ||
expect(endsWith(word, word.repeat(2))).toBe(false); | ||
}); | ||
}); |
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,7 @@ | ||
function equals(value, arg1) { | ||
import { bindNot } from '../../lib'; | ||
|
||
export function equals(value, arg1) { | ||
return value === arg1; | ||
} | ||
|
||
equals.negativeForm = 'notEquals'; | ||
|
||
export default equals; | ||
export const notEquals = bindNot(equals); |
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,9 +1,5 @@ | ||
import isNumeric from '../isNumeric'; | ||
import { isNumeric } from '../isNumeric'; | ||
|
||
function greaterThan(value, arg1) { | ||
export function greaterThan(value, arg1) { | ||
return isNumeric(value) && isNumeric(arg1) && Number(value) > Number(arg1); | ||
} | ||
|
||
greaterThan.alias = 'gt'; | ||
|
||
export default greaterThan; |
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,9 +1,5 @@ | ||
import isNumeric from '../isNumeric'; | ||
import { isNumeric } from '../isNumeric'; | ||
|
||
function greaterThanOrEquals(value, arg1) { | ||
export function greaterThanOrEquals(value, arg1) { | ||
return isNumeric(value) && isNumeric(arg1) && Number(value) >= Number(arg1); | ||
} | ||
|
||
greaterThanOrEquals.alias = 'gte'; | ||
|
||
export default greaterThanOrEquals; |
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.