Skip to content
This repository has been archived by the owner on Dec 5, 2017. It is now read-only.
/ pathly Public archive

Define JavaScript Objects through literal paths

License

Notifications You must be signed in to change notification settings

zanona/pathly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pathly

Build Status

Pathly is a smart script for creating JavaScript objects based on strings with literal paths.

The idea for creating this script came from the often needed functionality to convert data when submitting HTML forms.

var dataHolder = {};
pathly(dataHolder, 'people[0].name.first', 'John');
pathly(dataHolder, 'people[0].name.Last', 'Downey');
pathly(dataHolder, 'people[0].age', '30');

This makes possible that any field inside an HTML form can be named accordingly to their JSON respectives, like:

<form>
    <input type='text' name='people[0].name.first'>
    <input type='text' name='people[0].name.last'>
    <input type='text' name='people[0].age'>
</form>

And a simple Javascript function that would run through all fields and add those to the dataHolder object could easily generate the output wished. For brevity, using jQuery, for example:

var holder = {};
$('form [name]').each(function (el) { pathly(holder, el.name, $(el).val()); });
// holder object inheriting all parameters defined on the form.

Installation

Pathly can run both server or client-side. For NodeJS simply run npm install codefolding/pathly.

For AMD projets I would recommend install it with volo through volo install codefolding/pathly

For client-side scripts simply include pathly.js to your project. <script src='pathly.j'></script>

Usage

Node/AMD

var pathly = require('pathly');
pathly(holderObj, 'name', 'value');

Script

pathly(holderObj, 'name', 'value');

If you have any suggestions please feel free to contribute by opening an issue or sending a pull request.

About

Define JavaScript Objects through literal paths

Resources

License

Stars

Watchers

Forks

Packages

No packages published