Skip to content

Instantly share code, notes, and snippets.

@camskene
Created April 8, 2019 01:06
Show Gist options
  • Save camskene/81a929bfd4d344586315cf93a6010663 to your computer and use it in GitHub Desktop.
Save camskene/81a929bfd4d344586315cf93a6010663 to your computer and use it in GitHub Desktop.
JS Bin Generate `rule` with versions. Generate `ruleGroup` // source https://jsbin.com/kemexeh
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Generate `rule` with versions. Generate `ruleGroup`">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
'use strict';
function generateRule() {
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var _ref$id = _ref.id;
var id = _ref$id === undefined ? '' : _ref$id;
var _ref$name = _ref.name;
var name = _ref$name === undefined ? '' : _ref$name;
var rule = {
id: id,
name: name
};
var versions = [];
var maxNumVersions = 5;
for (var i = 0; i < maxNumVersions; i++) {
versions.push(Object.assign({}, rule, { id: rule.id + ':' + i }));
}
return Object.assign({}, rule, { versions: versions });
}
function generateRules() {
var rules = [];
var maxNumRules = 3;
for (var i = 0; i < maxNumRules; i++) {
rules.push(generateRule({
name: 'Rule #' + i,
id: '' + i
}));
}
return rules;
}
function generateRuleGroup() {
var _ref2 = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var _ref2$id = _ref2.id;
var id = _ref2$id === undefined ? '' : _ref2$id;
var _ref2$name = _ref2.name;
var name = _ref2$name === undefined ? '' : _ref2$name;
var group = {
id: id,
name: name
};
var rules = generateRules();
return Object.assign({}, group, { rules: rules });
}
function generateRuleGroups() {
var groups = [];
var maxNumGroups = 3;
for (var i = 0; i < maxNumGroups; i++) {
groups.push(generateRuleGroup({
name: 'Rule Group #' + i,
id: '' + i
}));
}
return groups;
}
console.clear();
console.log('groups:', generateRuleGroups());
</script>
<script id="jsbin-source-javascript" type="text/javascript">function generateRule({ id = '', name = '' } = {}) {
let rule = {
id,
name,
};
let versions = [];
let maxNumVersions = 5;
for (let i = 0; i < maxNumVersions; i++) {
versions.push(Object.assign({}, rule, { id: `${rule.id}:${i}`}));
}
return Object.assign({}, rule, { versions });
}
function generateRules() {
let rules = [];
let maxNumRules = 3;
for (let i = 0; i < maxNumRules; i++) {
rules.push(generateRule({
name: `Rule #${i}`,
id: `${i}`,
}));
}
return rules;
}
function generateRuleGroup({ id = '', name = '' } = {}) {
let group = {
id,
name,
};
let rules = generateRules();
return Object.assign({}, group, { rules });
}
function generateRuleGroups() {
let groups = [];
let maxNumGroups = 3;
for (let i = 0; i < maxNumGroups; i++) {
groups.push(generateRuleGroup({
name: `Rule Group #${i}`,
id: `${i}`,
}));
}
return groups;
}
console.clear();
console.log('groups:', generateRuleGroups())
</script></body>
</html>
'use strict';
function generateRule() {
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var _ref$id = _ref.id;
var id = _ref$id === undefined ? '' : _ref$id;
var _ref$name = _ref.name;
var name = _ref$name === undefined ? '' : _ref$name;
var rule = {
id: id,
name: name
};
var versions = [];
var maxNumVersions = 5;
for (var i = 0; i < maxNumVersions; i++) {
versions.push(Object.assign({}, rule, { id: rule.id + ':' + i }));
}
return Object.assign({}, rule, { versions: versions });
}
function generateRules() {
var rules = [];
var maxNumRules = 3;
for (var i = 0; i < maxNumRules; i++) {
rules.push(generateRule({
name: 'Rule #' + i,
id: '' + i
}));
}
return rules;
}
function generateRuleGroup() {
var _ref2 = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var _ref2$id = _ref2.id;
var id = _ref2$id === undefined ? '' : _ref2$id;
var _ref2$name = _ref2.name;
var name = _ref2$name === undefined ? '' : _ref2$name;
var group = {
id: id,
name: name
};
var rules = generateRules();
return Object.assign({}, group, { rules: rules });
}
function generateRuleGroups() {
var groups = [];
var maxNumGroups = 3;
for (var i = 0; i < maxNumGroups; i++) {
groups.push(generateRuleGroup({
name: 'Rule Group #' + i,
id: '' + i
}));
}
return groups;
}
console.clear();
console.log('groups:', generateRuleGroups());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment