aboutsummaryrefslogtreecommitdiff
path: root/examples/js
diff options
context:
space:
mode:
authorJay Liu <[email protected]>2013-11-05 17:06:36 -0700
committerJay Liu <[email protected]>2013-11-05 17:06:36 -0700
commite9d866ca2c92dcbc1129c83970cf73a0ab401831 (patch)
tree8f72cbe2aa109fb8aacf96dc1e74f23e11d198fd /examples/js
parent229f9b9d04bab0d57d575b71f2f8a281e53a58ec (diff)
downloadfaker-e9d866ca2c92dcbc1129c83970cf73a0ab401831.tar.xz
faker-e9d866ca2c92dcbc1129c83970cf73a0ab401831.zip
Update build with (working) Tree module
Diffstat (limited to 'examples/js')
-rw-r--r--examples/js/Faker.js85
1 files changed, 48 insertions, 37 deletions
diff --git a/examples/js/Faker.js b/examples/js/Faker.js
index 0691990a..1df2b6a8 100644
--- a/examples/js/Faker.js
+++ b/examples/js/Faker.js
@@ -17,7 +17,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-/*************** AUTOGENERATED @ 1383662792637 ***************
+/*************** AUTOGENERATED @ 1383696373283 ***************
WARNING: THIS FILE WAS AUTOGENERATED BY THE FAKER BUILD SCRIPT
MODIFYING THIS FILE IS FINE, BUT YOU REALLY SHOULD BE MODIFYING
THE LIBRARY DIRECTLY AND REGENERATING THIS FILE USING BUILD.js!!!!
@@ -392,51 +392,62 @@ Faker.Helpers.userCard = function () {
};
Faker.Tree = {};
-Faker.Tree.createTree = function (depth, width, obj) {
+Faker.Tree.clone = function clone(obj) {
+ if (obj == null || typeof(obj) != 'object')
+ return obj;
- if (!obj) {
- throw {
- name: "ObjectError",
- message: "there needs to be an object passed in",
- toString: function () {
- return this.name + ": " + this.message
- }
- };
- }
+ var temp = obj.constructor(); // changed
- if (width <= 0) {
- throw {
- name: "TreeParamError",
- message: "width must be greater than zero",
- toString: function () {
- return this.name + ": " + this.message
- }
- };
- }
+ for (var key in obj) {
+ temp[key] = this.clone(obj[key]);
+ }
+ return temp;
+ };
- var newObj = clone(obj);
+Faker.Tree.createTree = function (depth, width, obj) {
+ if (!obj) {
+ throw {
+ name: "ObjectError",
+ message: "there needs to be an object passed in",
+ toString: function () {
+ return this.name + ": " + this.message
+ }
+ };
+ }
- for (var prop in newObj) {
- if (newObj.hasOwnProperty(prop)) {
- var value = null;
- if (newObj[prop] !== "__RECURSE__") {
- value = eval(newObj[prop]);
- }
- else {
- if (depth !== 0) {
- value = [];
- for (var i = 0; i < width; i++) {
- value.push(createTree(depth - 1, width, obj));
+ if (width <= 0) {
+ throw {
+ name: "TreeParamError",
+ message: "width must be greater than zero",
+ toString: function () {
+ return this.name + ": " + this.message
+ }
+ };
+ }
+
+ var newObj = this.clone(obj);
+
+ for (var prop in newObj) {
+ if (newObj.hasOwnProperty(prop)) {
+ var value = null;
+ if (newObj[prop] !== "__RECURSE__") {
+ value = eval(newObj[prop]);
+ }
+ else {
+ if (depth !== 0) {
+ value = [];
+ for (var i = 0; i < width; i++) {
+ value.push(this.createTree(depth - 1, width, obj));
+ }
}
}
- }
- newObj[prop] = value;
+ newObj[prop] = value;
+ }
}
- }
- return newObj;
-};
+ return newObj;
+ };
Faker.random = {};
Faker.random.number = function (range) {