Skip to content

Commit

Permalink
add regex condition
Browse files Browse the repository at this point in the history
  • Loading branch information
lagden committed Mar 7, 2022
1 parent 3a62b65 commit a546557
Show file tree
Hide file tree
Showing 11 changed files with 1,995 additions and 3,665 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.yml
Expand Up @@ -33,6 +33,8 @@ rules:
padding-line-between-statements: off
no-undef-init: off
no-new-func: off
# no-unused-vars: off
# no-useless-escape: off
unicorn/filename-case: off
unicorn/prevent-abbreviations: off
unicorn/no-reduce: off
Expand Down
34 changes: 22 additions & 12 deletions README.md
Expand Up @@ -37,8 +37,10 @@ const data = {
age: 65,
gender: 'F',
city: 'São Paulo',
country: 'Brazil',
phone: '(11) 988889999',
hasCar: true,
colors: ['red', 'blue']
colors: ['red', 'blue'],
}

const conditions = [
Expand All @@ -48,31 +50,39 @@ const conditions = [
{
field: 'gender',
operator: 'eq',
value: 'F'
value: 'F',
}, {
field: 'age',
operator: 'gt',
value: 21
value: 21,
}, {
field: 'phone',
operator: 'regex',
value: /\(\d{2}\)\s(\d{8,9})/i,
}, {
join_operator: 'or',
args: [
{
field: 'city',
operator: 'assigned',
value: false
value: false,
}, {
field: 'colors',
field: 'country',
operator: 'intersection',
value: ['blue', 'green']
}
]
value: ['Japan', 'Brazil'],
},
],
}, {
field: 'hasCar',
operator: 'eq',
value: true
}
]
}
value: true,
}, {
field: 'colors',
operator: 'intersection',
value: ['blue', 'green', 123],
},
],
},
]

const isValid = condition(conditions)
Expand Down
2 changes: 1 addition & 1 deletion bin/helper/fn
Expand Up @@ -31,7 +31,7 @@ load_env() {
gen_env() {
_DIR="$(cd $(dirname $0) && pwd)"
_BIN_DIR="$(cd $DIR/.. && pwd)"
GEN_ENV="${2:-$_BIN_DIR}/node/envs"
GEN_ENV="${2:-$_BIN_DIR}/node/envs.js"

if test -z $1; then
abort "Missing output"
Expand Down
20 changes: 0 additions & 20 deletions bin/node/envs

This file was deleted.

17 changes: 17 additions & 0 deletions bin/node/envs.js
@@ -0,0 +1,17 @@
#!/usr/bin/env node

import process from 'node:process'

const {ENV_INCLUDE = ''} = process.env
const vals = ENV_INCLUDE.split(' ')
const envs = vals.map(v => `envs.${v} = '${process.env?.[v]}'`)

const template = `const envs = {}
${envs.join('\n')}
export default envs`

// process.stderr.write(template)
console.log(template)
process.exit(0)
19 changes: 8 additions & 11 deletions bin/node/pkg.js
Expand Up @@ -42,17 +42,14 @@ function getLatestVersionPackage(data, prop) {
return Promise.allSettled(
keys.map(async name => {
const cmd = `npm show ${name} version`
try {
let {stdout: version} = await exec(cmd)
version = String(version).replace('\n', '')
if (version && data[name] !== String(version)) {
cc++
process.stdout.write(`${name} --> ${version}\n`)
packageJson[prop][name] = version
return {name, version}
}
} catch {}
return Promise.reject()
let {stdout: version} = await exec(cmd)
version = String(version).replace('\n', '')
if (version && data[name] !== String(version)) {
cc++
process.stdout.write(`${name} --> ${version}\n`)
packageJson[prop][name] = version
return {name, version}
}
}),
)
}
Expand Down

0 comments on commit a546557

Please sign in to comment.