<commit_before># jsmix
A simple tool to easily map data onto model objects. In other words this tool helps you with deserializing data into full-fledged model objects with methods. My aim was to have a simple to use tool, that you can use to mix methods with data after you got your JSON back from a REST API.

## How to use
Here's how it works in real life. You still need to define your model on the client side:

	var Employee = function() {
	}
	
	Employee.prototype.getName = function() {
		return this.firstName + ' ' + this.lastName;
	}

Then if you have a REST service "getAnEmployee", that returns a JSON like this:

	{
		"epmloyee": {
			"firstName": "John",
			"lastName": "Doe",
			"salary": 100000,
			"age": 33	
		}
	}

you could say in AngularJS (for example):

	http.get("/getAnEmployee").then( function(result) {
		console.log(
			JSMix(result).withObject(Employee.prototype, "employee").build().getName()
		);
	});

Which will then log "<NAME>" for you.

<commit_msg>Updated for nested object support<commit_after># jsmix
A simple tool to easily map data onto model objects. In other words this tool helps you with deserializing data into full-fledged model objects with methods. My aim was to have a simple to use tool, that you can use to mix methods with data after you got your JSON back from a REST API.

This is a WIP project, but it's already usable. There's no minified version yet, that should be almost the next thing I'll do.  

## How to use
Here's how it works in real life. You still need to define your model on the client side:

	var Employee = function() {
	}
	
	Employee.prototype.getName = function() {
		return this.firstName + ' ' + this.lastName;
	}

Then if you have a REST service "getAnEmployee", that returns a JSON like this:

	{
		"epmloyee": {
			"firstName": "John",
			"lastName": "Doe",
			"salary": 100000,
			"age": 33	
		}
	}

you could say in AngularJS (for example):

	http.get("/getAnEmployee").then( function(result) {
		console.log(
			JSMix(result).withObject(Employee.prototype, "employee").build().getName()
		);
	});

Which will then log "<NAME>" for you.

## Parameter explained

A slightly more complex example would look like:

	var result = JSMix(sampleData)
		.withObject(Employee.prototype, "employees")
		.withObject(Pet.prototype, "employees.pet")
		.build();
 
 So the parameter to the JSMix(data) call, data could be a JSON string, or an object. The build() just returns the object, with all classes mixed.
 The withObject(prototype, path) call is the one to define class mappings.
 Here "path" can be any chain of nested objects separated with a dot. For example in this case "epmloyees.pet".
 JSMix will find out if an object is an array, and will recursively apply the remaining part of the path to every item in it.
 You can also use "*" in the path, and this will apply the remaining path to every item in the object (even if it's not an array).
     
 
 
{'fraction_non_alphanumeric': 0.09211873080859775, 'fraction_numerical': 0.005458887751620608, 'mean_word_length': 3.75974025974026, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6356323', 'n_tokens_mistral': 945, 'n_tokens_neox': 847, 'n_words': 408}