parsifal
A pure JavaScript port of jQuery's .val() method.
Last updated 11 years ago by V1 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install parsifal 
SYNC missed versions from official npm registry.

Parsifal

Parsifal is a pure JavaScript port of jQuery's .val() method which is used to retrieve values from from elements.

Installation

The package can be used through browserify as the module contents are exposes through the module.exports interface. Therefor this package is installable using npm:

npm install --save parsifal

Usage

This module exposes the parser as a single function. To use it in your library simple require the module:

'use strict';

var val = require('parsifal');

Now that we have access to the method, we can simply start parsing the value's out of elements:

var value = val(document.getElementByTagName('input')[0]);

And that's it. Super simple, super effective.

parsifal.parser

We expose dedicated parsers for elements based on their type or nodeName. If you wish to add more or change a parser simply add or override the property with a new method. Check the source for the current dedicated parsers.

//
// EXAMPLE: Simple override or introduction of the radio button parser so it
// returns booleans instead of strings.
//
parsifal.parser.radio = function radio(element) {
  return ((element.getAttribute('value') !== null ? element.value : 'on') === 'on';
};

The following methods are mostly internally but are to useful for other to not expose them.

parsifal.trim()

parsifal.trim(string)

Trim the whitespace of a string from the right and left side.

var str = parsifal.trim('  fooo   ');
// str is now 'foo'

parsifal.text()

parsifal.text(element)

Get the text from a given element without all the nasty HTML.

var text = parsifal.text(document.getElementById('example'));

License

MIT

Current Tags

  • 0.0.0                                ...           latest (11 years ago)

1 Versions

  • 0.0.0                                ...           11 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |