janearc / deep-grep Goto Github PK
View Code? Open in Web Editor NEWToo many haystacks, not enough needles
License: Other
Too many haystacks, not enough needles
License: Other
Can we have a deep clone based on a match
e.g.
var haystack = [
'zebra', 'lion', [
'tiger', 'unicorn', 'emperor penguin'
],
'leprechaun',
'cockerel'
];
var needles = dg.pickDeep( list, function (t) {
if (new RegExp( ('(unicorn|leprechaun)s?' ).test(t))) return true
} );
yields:
['leprechaun',['unicorn']];
It probably should be
So if we have a list
that looks like:
[
{ 'user-name': 'jane', 'user-id': 692, 'home': '/usr/people/jane' },
{ 'user-name': 'federico', 'user-id': 693, 'home': '/usr/people/federico' },
]
right now dg would (I think…) return the hash tuples like:
[
{ 'user-name': 'jane' },
{ 'user-id': '693' },
{ 'home': '/usr/people/jane' }
]
if we called it like
var results = require( 'deep-grep' ).deeply( list, /[a3]/, {
'return-hash-tuples': true,
'check-hash-values': true,
'check-hash-keys': true
} );
which is what I want some of the time, but I also want to be able to return the whole object (so, { 'user-name': 'jane', 'user-id': 692, 'home': '/usr/people/jane' }
, rather than tuples/kv pairs). The logic for this is not straightforward because there's no state kept in deeply
about the object it's grepping; rather it just keeps track of the value and the key. I think.
I think it's probably best to just merge in jagrep
. There's a lot of overlap. It's all listy things to do.
var within = dg.in( [ 1, 2, 3, 4], 1 ); // true
var within = dg.in( [ 1, 2, 3, 4], [ 2, 3 ] ); // true
var within = dg.in( [ 1, 2, 3, 4], [ 2, 3, 4, 5 ] ); // returns [ 2, 3, 4 ] ?
var from = {
foo: 'bar',
baz: 'bletch'
}
var to = {
qip: 'quux'
}
this presents an ugliness in the way javascript handles objects. There is no way to refer to multiple values of an object by its keys.
dg.coalesce_object( from, to, {
'keys': [ 'foo', 'baz' ],
'return-clone': true
} )
would allow me to make a clone that looked like:
{
qip: 'quux'
foo: 'bar',
baz: 'bletch'
}
and alternatively if return-clone
is false, to
would be munged.
Some of the wording is awkward, syntax hilighting is not enabled.
why does one use typeof
vs constructor
(see this line)
This parameter is specified in the docs but I never got around to writing it, and is considered by me to be core functionality (because there is so much intermingling of keys/methods in objects in js).
Obviously since deeply flattens, and I use this functionality elsewhere, it would be good to just expose that functionality.
use the wrapper for testing expressions vs regexes rather than repeating code in each method
So ordinarily I do something like:
my $unique = [ keys %{ map { $_ => 1 } @some_list } ]
To get the unique elements of a list. Obviously this idiom won't work for lots of reasons in node, but it would be nice to be able to add a { unique: true }
parameter to deeply()
. In fact, I could probably use this today.
namespace contamination abounds. clean up the usage for the singleton
it is kind of mentioned RIGHT THERE IN THE README, jane
There is no real way to grep through a promise. Since Sendak uses promises extensively, dg
is unwelcome in a large number of places. Fix that.
a way to pass the state (list element) and the entire list to object methods (to turn lists into state machines).
In theory it should be possible to override the "push" and "pop" methods that deep-grep
uses to e.g., pull records… out of riak. or out of a hadoop cluster. or whatever. but there's no reason the list has to be an actual in-memory list; it can just be a "list-like thing in the sky."
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.