Skip to content

Commit

Permalink
v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Jul 1, 2020
1 parent 14c7394 commit 4134ca7
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 295 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "patrun",
"version": "3.0.0",
"version": "4.0.0",
"description": "A fast pattern matcher on JavaScript object properties.",
"homepage": "https://github.com/rjrodger/patrun",
"keywords": [
Expand All @@ -19,11 +19,12 @@
"scripts": {
"test": "lab -v -L -P test -t 90 -r console -o stdout -r html -o test/coverage.html",
"coveralls": "lab -s -P test -r lcov -I URL,URLSearchParams | coveralls",
"prettier": "prettier --write --no-semi --single-quote patrun.js lib/*.js test/*.js",
"prettier": "prettier --write --no-semi --single-quote patrun.js *.js test/*.js",
"clean": "rm -rf node_modules yarn.lock package-lock.json",
"reset": "npm run clean && npm i && npm test",
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags;",
"repo-publish": "npm run prettier && npm run reset && npm run repo-tag && npm publish --registry http://registry.npmjs.org "
"repo-publish": "npm run clean && npm -i && npm run repo-publish-quick",
"repo-publish-quick": "npm run prettier && npm run reset && npm run repo-tag && npm publish --registry http://registry.npmjs.org "
},
"license": "MIT",
"files": [
Expand Down
50 changes: 25 additions & 25 deletions patrun.js
@@ -1,6 +1,6 @@
/* Copyright (c) 2013-2020 Richard Rodger, MIT License, https://github.com/rjrodger/patrun */

;(function() {
;(function () {
'use strict'
var root = this
var previous_patrun = root.patrun
Expand All @@ -10,23 +10,23 @@
if (!gex)
throw new Error('patrun requires gex, see https://github.com/rjrodger/gex')

var patrun = (root.patrun = function(custom) {
var patrun = (root.patrun = function (custom) {
custom = custom || {}

var self = {}
var top = {}

// Provide internal search order structure
self.top = function() {
self.top = function () {
return top
}

self.noConflict = function() {
self.noConflict = function () {
root.patrun = previous_patrun
return self
}

self.add = function(pat, data) {
self.add = function (pat, data) {
pat = { ...pat }

var customizer =
Expand All @@ -36,7 +36,7 @@
var plains = []
var gexers = []

keys.forEach(function(key) {
keys.forEach(function (key) {
var val = pat[key]
if (null == val) return

Expand Down Expand Up @@ -117,17 +117,16 @@
var g = (keymap.g = keymap.g || {})
var ga = (g[key] = g[key] || [])
ga.push(gexer)
ga.sort(function(a, b) {
ga.sort(function (a, b) {
return a.val$ < b.val$
})
}

self.findexact = function(pat) {
self.findexact = function (pat) {
return self.find(pat, true)
}

self.find = function(pat, exact, collect, depth) {
depth = depth || 0
self.find = function (pat, exact, collect) {
if (null == pat) return null

var keymap = top
Expand Down Expand Up @@ -162,7 +161,7 @@

if (nextkeymap) {
foundkeys[key] = true

if (keymap.s) {
stars.push(keymap.s)
}
Expand All @@ -186,10 +185,11 @@
keymap = null
}

if (null == keymap &&
0 < stars.length &&
(null == data || (collect && !exact))
) {
if (
null == keymap &&
0 < stars.length &&
(null == data || (collect && !exact))
) {
keymap = stars.pop()
}
} while (keymap)
Expand All @@ -212,7 +212,7 @@
return collect ? collection : data
}

self.remove = function(pat) {
self.remove = function (pat) {
var keymap = top
var data = null
var key
Expand Down Expand Up @@ -247,7 +247,7 @@
}

// values can be verbatim, glob, or array of globs
self.list = function(pat, exact) {
self.list = function (pat, exact) {
pat = pat || {}

function descend(keymap, match, missing, acc) {
Expand Down Expand Up @@ -282,7 +282,7 @@
acc.push({
match: valitermatch,
data: nextkeymap.d,
find: nextkeymap.f
find: nextkeymap.f,
})
}

Expand Down Expand Up @@ -310,21 +310,21 @@
acc.push({
match: {},
data: top.d,
find: top.f
find: top.f,
})
}

descend(top, {}, { ...pat }, acc)
return acc
}

self.toString = function(first, second) {
self.toString = function (first, second) {
var tree = true === first ? true : !!second

var dstr =
'function' === typeof first
? first
: function(d) {
: function (d) {
return 'function' === typeof d
? '<' + d.name + '>'
: '<' + d + '>'
Expand Down Expand Up @@ -354,10 +354,10 @@
if (n.v) {
d++
var pa = Object.keys(n.v)
var pal = pa.filter(function(x) {
var pal = pa.filter(function (x) {
return !x.match(/[*?]/)
})
var pas = pa.filter(function(x) {
var pas = pa.filter(function (x) {
return x.match(/[*?]/)
})
pal.sort()
Expand Down Expand Up @@ -394,10 +394,10 @@

self.inspect = self.toString

self.toJSON = function(indent) {
self.toJSON = function (indent) {
return JSON.stringify(
top,
function(key, val) {
function (key, val) {
if ('function' === typeof val) return '[Function]'
return val
},
Expand Down
14 changes: 7 additions & 7 deletions test/bench.js
Expand Up @@ -72,7 +72,7 @@ function run0() {
var s0 = new Benchmark.Suite()

for (var i = 0; i < 100; i++) {
s0.add('top-find:' + i, function() {
s0.add('top-find:' + i, function () {
for (var j = 0; j < i; j++) {
var p = {}
p[k0[i]] = k0[i]
Expand All @@ -81,7 +81,7 @@ function run0() {
})
}

s0.on('cycle', function(event) {
s0.on('cycle', function (event) {
console.log(
event.target.toString() + ':' + util.inspect(process.memoryUsage())
)
Expand All @@ -93,15 +93,15 @@ function run1() {

var i = 0

s1.add('top-find', function() {
s1.add('top-find', function () {
var p = {}
p[k0[i]] = k0[i]
p0.find(p)
i++
i %= 100
})

s1.on('cycle', function(event) {
s1.on('cycle', function (event) {
console.log(
event.target.toString() + ':' + util.inspect(process.memoryUsage())
)
Expand All @@ -123,8 +123,8 @@ function run2() {

s2.add(
'd2-find ' + ijmax[w][0] + ',' + ijmax[w][1],
(function(w, imax, jmax) {
return function() {
(function (w, imax, jmax) {
return function () {
var p = {},
i = ij[w][0],
j = ij[w][1]
Expand All @@ -145,7 +145,7 @@ function run2() {
}
}

s2.on('cycle', function(event) {
s2.on('cycle', function (event) {
console.log(
event.target.toString() + ':' + util.inspect(process.memoryUsage())
)
Expand Down

0 comments on commit 4134ca7

Please sign in to comment.