0.0.4 • Published 9 years ago

search-template-form v0.0.4

Weekly downloads
17
License
-
Repository
-
Last release
9 years ago

search-template-form

This module has object for incapsulate search template, which used for generate search query to the web site.

USEFUL: Deserialize Href to an StForm object and serialize an StForm object to Href (which used as search template).

StForm object have next fields:

  • method : request method (default = "get")
  • host : include part of URL string without pathname and query string
  • action : relative href without hostname
  • params : array of objects like elements of form tag witch used to build query string
  • type : specifies the form type, for example, "search", "login", "subscribe", "buy", "feedback", "comment" etc.

Object (element of params) have some or all of the following fields:

  • type
  • name
  • value

Install

$ npm install search-template-form

Usage

var href = "https://www.google.com.ua/search?q=&sourceid=chrome&es_sm=93&ie=UTF-8";
var formObj = new StForm();

formObj.fromHref(href);
console.log(formObj.host);

formObj.setSearchText("search-template-form");

console.log(formObj.toHref());

API

stForm.parse(string)

Take a URL string, and return an stForm object.

stForm.stringify(stForm object)

Stringify an stForm object into a URL string.

Methods

.toHref()

Stringify self data into a URL string. Return (string).

.fromHref(string)

Take a URL string, and parse into self data.

.setSearchText(string)

Set the search text as value of associated request parameter. First look for params[].type = "search", then for "text" and lastly for params[].type = "". Return (boolean) true if parameter is set.

Test

npm test

License

MIT © Taras Panasyuk

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago