Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Adds name for unnamed functions #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/private/evaluate-rule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Rule } from '../interfaces'

export default (rule: Rule, data: object): boolean => {
const evaluateRule = (rule: Rule, data: object): boolean => {
if (typeof rule === 'function') {
return rule(data)
}
Expand All @@ -11,3 +11,5 @@ export default (rule: Rule, data: object): boolean => {

return false
}

export default evaluateRule
4 changes: 3 additions & 1 deletion src/private/is-escaped.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
const isEscapedRegex = /^@@/
export default (arg: any): Boolean => isEscapedRegex.test(arg)
const isEscaped = (arg: any): Boolean => isEscapedRegex.test(arg)

export default isEscaped
4 changes: 3 additions & 1 deletion src/private/make-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import stripAt from './strip-at'

// makeArgs will sort out if the leftArg and rightArg are lenses or
// static and return the the data that your predicates needs.
export default (data: Object, ...args: any[]): any[] => args.map(x => {
const makeArgs = (data: Object, ...args: any[]): any[] => args.map(x => {
if (isLookup(x)) {
return get(data, stripAt(x))
} else if (isOpticOrRule(x)) {
Expand All @@ -15,3 +15,5 @@ export default (data: Object, ...args: any[]): any[] => args.map(x => {

return stripAt(x)
})

export default makeArgs
9 changes: 5 additions & 4 deletions src/private/make-array-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import stripAt from './strip-at'

// makeArgs will sort out if the leftArg and rightArg are lookups or
// static and return the the data that your predicates needs.
export default (data: Object, ...args: any[]): any[] =>
args.map(x => isLookup(x)
? get(data, stripAt(x))
: stripAt(x))
const makeArrayArgs = (data: Object, ...args: any[]): any[] => {
return args.map(x => isLookup(x) ? get(data, stripAt(x)) : stripAt(x))
}

export default makeArrayArgs
4 changes: 3 additions & 1 deletion src/private/make-with-context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FactoryArgs, Rule, RegentFn } from '../interfaces'
import makeArrayArgs from './make-array-args'

export default (fn: Function, name?: string) => {
const makeWithContext = (fn: Function, name?: string) => {
return (left: FactoryArgs, right: FactoryArgs, context = '__'): Rule => {
const ruleFn = (data: object): boolean =>
fn(...makeArrayArgs(data, left, right), context, data)
Expand All @@ -23,3 +23,5 @@ export default (fn: Function, name?: string) => {
return ruleFn
}
}

export default makeWithContext