-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nicolaslabbe
committed
Aug 11, 2016
1 parent
2c6610b
commit 857a64e
Showing
7 changed files
with
372 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
|
||
exports.default = removeDuplicateAttr; | ||
|
||
var _cli = require('../../cli'); | ||
|
||
function recurseDeleteKey(currentLevel, arrayKeyAttr) { | ||
var currentArray = arrayKeyAttr.slice(0); | ||
|
||
if (arrayKeyAttr.length === 1) { | ||
delete currentLevel[arrayKeyAttr[0]]; | ||
} | ||
|
||
Array.prototype.forEach.call(currentArray, function (key) { | ||
if (typeof currentLevel[key] !== 'undefined' && currentLevel[key] !== null) { | ||
currentLevel = currentLevel[key]; | ||
currentArray.shift(); | ||
recurseDeleteKey(currentLevel, currentArray); | ||
if ((typeof currentLevel === 'undefined' ? 'undefined' : _typeof(currentLevel)) === 'object' && Object.prototype.toString.call(currentLevel) === '[object Array]') { | ||
Array.prototype.forEach.call(currentLevel, function (item) { | ||
recurseDeleteKey(item, currentArray); | ||
}); | ||
} else { | ||
recurseDeleteKey(currentLevel, currentArray); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function removeDuplicateAttr(text, json) { | ||
var regAbe = /{{abe[\S\s].*?duplicate=['|"]([\S\s].*?['|"| ]}})/g; | ||
var matches = text.match(regAbe); | ||
var requiredValue = 0; | ||
var complete = 0; | ||
if (typeof matches !== 'undefined' && matches !== null) { | ||
|
||
Array.prototype.forEach.call(matches, function (match) { | ||
var keyAttr = (0, _cli.getAttr)(match, 'key'); | ||
|
||
if (typeof match !== 'undefined' && match !== null) { | ||
var arrayKeyAttr = keyAttr.split('.'); | ||
recurseDeleteKey(json, arrayKeyAttr); | ||
} | ||
}); | ||
} | ||
|
||
return json; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
|
||
var deep_value = function deep_value(obj, path) { | ||
|
||
if (path.indexOf('.') === -1) { | ||
return typeof obj[path] !== 'undefined' && obj[path] !== null ? obj[path] : null; | ||
} | ||
|
||
var pathSplit = path.split('.'); | ||
var res = JSON.parse(JSON.stringify(obj)); | ||
|
||
while (pathSplit.length > 0) { | ||
|
||
if (typeof res[pathSplit[0]] !== 'undefined' && res[pathSplit[0]] !== null) { | ||
if (_typeof(res[pathSplit[0]]) === 'object' && Object.prototype.toString.call(res[pathSplit[0]]) === '[object Array]') { | ||
var resArray = []; | ||
|
||
Array.prototype.forEach.call(res[pathSplit[0]], function (item) { | ||
resArray.push(deep_value(item, pathSplit.join('.').replace(pathSplit[0] + '.', ''))); | ||
}); | ||
res = resArray; | ||
pathSplit.shift(); | ||
} else { | ||
res = res[pathSplit[0]]; | ||
} | ||
} else { | ||
return null; | ||
} | ||
pathSplit.shift(); | ||
} | ||
|
||
return res; | ||
}; | ||
|
||
exports.default = deep_value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.