Skip to content

Commit

Permalink
chore: Add parse-form, fix build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
finom committed Jan 18, 2020
1 parent 2964be4 commit 1d2aa4b
Show file tree
Hide file tree
Showing 42 changed files with 10,993 additions and 41 deletions.
18 changes: 18 additions & 0 deletions packages/parse-form/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": [
"airbnb-base"
],
"rules": {
"indent": ["error", 4],
"no-var": "error",
"comma-dangle": ["error", "never"],
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }]
},
"env": {
"jasmine": true
},
"globals": {
"window": true
}
}
8 changes: 8 additions & 0 deletions packages/parse-form/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
*.log
.directory
coverage
.coveralls.yml
npm
bundle
/index.js
10 changes: 10 additions & 0 deletions packages/parse-form/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bundle
coverage
test
.eslintrc.json
.gitignore
.travis.yml
src.js
webpack.config.js
.coveralls.yml
.babelrc
21 changes: 21 additions & 0 deletions packages/parse-form/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Seemple.js

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE 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.
62 changes: 62 additions & 0 deletions packages/parse-form/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# seemple-parse-form [![npm version](https://badge.fury.io/js/seemple-parse-form.svg)](https://badge.fury.io/js/seemple-parse-form) [![Coverage Status](https://coveralls.io/repos/github/seemplejs/seemple-parse-form/badge.svg?branch=master)](https://coveralls.io/github/seemplejs/seemple-parse-form?branch=master) [![Build Status](https://travis-ci.org/seemplejs/seemple-parse-form.svg?branch=master)](https://travis-ci.org/seemplejs/seemple-parse-form)

The function binds named HTML form fields (input, select, textarea etc) contained at given HTML form to corresponding properties.

```html
<form class="my-form">
<input type="text" value="foo" name="x">
</form>
```

```js
const object = {};
parseForm(object, '.my-form');

// ...
console.log(object.x); // 'foo'
object.x = 'bar'; // changes input value to 'bar'
```

## Usage

In **browser environment** (or whatever environment where ``Seemple`` is global variable) ``Seemple`` is extended.
```html
<script src="path/to/seemple-parse-form.min.js"></script>
```

```js
Seemple.parseForm(object, form);
```

The bundle can be downloaded at [gh-pages branch](https://github.com/seemplejs/seemple-parse-form/tree/gh-pages)

-------------

In **CJS environment** ``Seemple`` is not extended.

```
npm install --save seemple-parse-form
```

```js
const parseForm = require('seemple-parse-form');
```


## API

The function accepts 4 arguments:
- ``object`` - an object (required)
- ``form`` - a selector, DOM node etc. of given form (custom selectors ``:sandbox`` and ``:bound(XXX)`` also acceptable) (required)
- ``callback`` - a function which will be called on every found field; accepts field name and field element itself
- ``eventOptions`` - event options which will be passed to every internal call of ``bindNode``.

Returns: parsed form element.


The third argument is usable when ``parseForm`` is used with ``Seemple.Object``: you can call ``addDataKeys`` method there.
```js
const form = parseForm(this, ':sandbox .foo', key => this.addDataKeys(key), {
getValueOnBind: false
});
```
3 changes: 3 additions & 0 deletions packages/parse-form/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
"presets": ["@babel/preset-env"]
}
Loading

0 comments on commit 1d2aa4b

Please sign in to comment.