
Security News
Rolldown Pulls Rust React Compiler Integration After Binary Size Increase
Rolldown paused Rust React Compiler integration after a 5MB binary size increase raised concerns about shipping React-specific code to all Vite users.
A normalization pattern to build, query, and manipulate everything.
(4/20/12) version 1.2.1 by Bemi Faison
genData is a recursive, depth-first iterator and generic parser, for querying objects. genData lets you control iteration and parsing behavior, along with the returned dataset.
Within web browsers, reference the gendata-min.js, as you would any external JavaScript file.
<script type="text/javascript" src="somepath/gendata-min.js"></script>
<script type="text/javascript">
// Your code that uses genData...
</script>
For Node, install genData source files manually, or via npm (recommended).
npm install genData
Then, for commonJS environments (like Node), require the genData module, and reference the exported genData function.
var genData = require('genData').genData;
// Your code that uses genData...
Warning: genData scans objects recursively!! Make sure to check for previously inspected objects, or avoid passing self-referencing structures!
genData translates anything into a dataset. A dataset is an array of objects with a common structure. By default, genData assigns a name and value member to dataset objects. The examples below, demonstrate how genData normalizes data, the first argument.
Use genData to normalize an object...
genData({hello: "world"});
/*
returns this array...
[
{
name: '',
value: {hello: 'world', pie: "sky"}
},
{
name: 'hello',
value: 'world'
},
{
name: 'pie',
value: 'sky'
}
]
*/
Use genData to normalize an array...
genData([9276, {ping: "pong"}, "foo"]);
/*
returns this array...
[
{
name: '',
value: [9276, {ping: "pong"}, "foo"]
},
{
name: '0',
value: 9276
},
{
name: '1',
value: {ping: "pong"}
},
{
name: 'ping',
value: 'pong'
},
{
name: '2',
value: 'foo'
}
]
*/
Use genData to normalize nothing...
genData();
/*
returns this array...
[
{
name: '',
value: undefined
}
]
*/
The second argument may be a function or array of functions, called parsers.
Use genData with a parser that manipulates members of each data object in the dataset...
genData(
[{hello: 'world', pie: "sky"}],
function () {
this.randId = Math.random();
delete this.name;
}
);
/*
returns this array...
[
{
value: {hello: 'world', pie: "sky"},
randId: 0.9093414132948965
},
{
value: 'world',
randId: 0.20426166336983442
},
{
value: 'sky',
randId: 0.5697704532649368
}
]
*/
Parsers also control what genData iterates and returns, by performing logic and setting iteration flags from the following function signature.
Use genData to query the numeric values of an object...
genData(
[10, ["echo", {top: 20}], true, 30, "charlie"],
function (name, value, parent, dataset, flags) {
flags.omit = typeof value !== 'number';
}
);
/*
returns this array...
[
{
name: '0',
value: 10
},
{
name: 'top',
value: 20
},
{
name: '3',
value: 50
}
]
*/
Use genData to capture all strings of an object...
genData(
[10, ["echo", {top: 20}], true, 30, "charlie"],
function (name, value, parent, dataset, flags) {
flags.omit = 1;
if (typeof value === 'string') {
dataset.push(value);
}
}
);
/*
returns this array...
[
'echo',
'charlie'
]
*/
Generators are functions that capture and extend complex parsing logic.
For example, this generator returns all found functions.
var extractFncs = new genData(
function (name, value, parent, dataset, flags) {
flags.omit = 1;
if (typeof value === 'function') {
dataset.push(value);
}
}
);
You can then pass anything to the @extractFncs@ generator, and it will call genData as if you included the parsers manually.
var foundFncs = extractFns(aBigConfigObject);
You can also spawn new generators and pass (additional) parser functions to any generator. Below, we'll spawn a generator from our @extractFncs@ generator, to further exclude functions that have a length greater than 2.
var extractFncsLessThan3 = new extractFncs(
function (name, value, parent, dataset) {
if (typeof value === 'function' && value.length > 2) {
dataset.pop();
}
}
);
genData, along with each generator, supplies a prototype chain to each data object. Below, we define an @.isArray()@ method to the genData prototype, then access this method through a generator.
genData.prototype.isArray = function () {
return !!~{}.toString.call(this.value).indexOf('y');
};
var extractArrays = new genData(
function (name, value, parent, dataset, flags) {
flags.omit = !this.isArray();
}
);
You may also pass a third parameter to genData (or a generator), an object or function, to serve as the prototype for the returned data objects.
var dataset = genData(
stuff,
[], // this could also be "falsy"
{
myFamiliarMethod: function () {
// "this" will be the data object
}
}
);
dataset[0].myFamiliarMethod();
Note: Generators only branch/extend the genData prototype chain.
genData is available under the terms of the MIT-License.
Copyright 2011, Bemi Faison
FAQs
A normalization pattern to build, query, and manipulate everything.
The npm package genData receives a total of 19 weekly downloads. As such, genData popularity was classified as not popular.
We found that genData demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Rolldown paused Rust React Compiler integration after a 5MB binary size increase raised concerns about shipping React-specific code to all Vite users.

Security News
/Research
Mini Shai-Hulud expands into the Go ecosystem after hitting LeoPlatform npm packages and targeting GitHub Actions workflows.

Security News
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.