HerrHase 1 year ago
commit 9d2b1f71f9

121
.gitignore vendored

@ -0,0 +1,121 @@
# ---> Node
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
.env.production
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
public

1761
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,24 @@
{
"name": "@helpers/siteomat-query",
"version": "0.1.0",
"build": "webpack",
"author": "Björn Hase <me@herr-hase.wtf>",
"main": "index.js",
"repository": {
"type": "git",
"url": "git@gitea.node001.net:HerrHase/siteomat-query.git"
},
"scripts": {
"test": "mocha"
},
"description": "A Site-O-Mat Query",
"dependencies": {
"assign-deep": "^1.0.1",
"lodash.merge": "^4.6.2",
"lodash.orderby": "^4.6.0"
},
"devDependencies": {
"chai": "^4.3.7",
"mocha": "^10.2.0"
}
}

@ -0,0 +1,76 @@
class Filter {
constructor(options) {
this._options = options
}
_eq(value, key, result) {
let isValid = false
if (result[key] === value) {
isValid = true
}
return isValid
}
_neq(value, key, result) {
let isValid = false
if (result[key] !== value) {
isValid = true
}
return isValid
}
_in(value, key, result) {
let isValid = false
if (!result[key]) {
isValid = false
}
if (Array.isArray(value)) {
let found = false
// run through array
value.forEach((v, index) => {
if (result[key].indexOf(v) !== -1) {
found = true
}
})
if (found) {
isValid = true
}
} else {
if (result[key].indexOf(value) !== -1) {
isValid = true
}
}
return isValid
}
validate(result) {
let isValid = true
for (const [key, value] of Object.entries(this._options)) {
const operators = Object.keys(value)
operators.forEach((operator) => {
if (!this[operator](value[operator], key, result)) {
isValid = false
}
})
}
return isValid
}
}
module.exports = Filter

@ -0,0 +1,13 @@
const Filter = require('./src/filter.js')
const filter = new Filter({
view: {
_eq: 'post.nj'
}
})
const v = filter.validate({
view: 'post.njk'
})
console.log(v)

@ -0,0 +1,75 @@
const { assert } = require('chai')
const fs = require('fs')
describe('Filter', function () {
// get function
const Filter = require('./../src/filter.js')
// check results
it('_eq', function() {
const filter = new Filter({
view: {
_eq: 'post.njk'
}
})
const data = {
view: 'post.njk'
}
assert.equal(filter.validate(data), true)
})
it('_neq', function() {
const filter = new Filter({
view: {
_neq: 'post.njk'
}
})
const data = {
view: 'blog.njk'
}
assert.equal(filter.validate(data), true)
})
it('_in single', function() {
const filter = new Filter({
tags: {
_in: 'monday'
}
})
const data = {
tags: [
'monday', 'friday'
]
}
assert.equal(filter.validate(data), true)
})
it('_in array', function() {
const filter = new Filter({
tags: {
_in: [
'monday'
]
}
})
const data = {
tags: [
'monday', 'friday'
]
}
assert.equal(filter.validate(data), true)
})
})
Loading…
Cancel
Save