scheme

0.0.2 • Public • Published

SCHEME.js

Rick Ross - Stay Schemin

Installation

npm install scheme

Synopsys

This was created originally to help construct request URI's, by building each part of the URI separately I could easily have variables in the URI. This helps for oAuth.

Build from object / json

var build = scheme.build({
    scheme: 'http',
    host: 'localhost',
    port: '3000',
    path: [ 'application', 'login' ],
    query: { user: 'github' }
});
console.log(build);

Return

http://localhost:3000/application/login?user=github

Synonyms

I realize that a lot of people (including myself) struggle with the names of each piece of a URI, knowing this, I made multiple things map to the same, using synonyms.

["url","uri"],
["scheme","protocol"],
["username","user"],
["password","pass"],
["domain","host","domains","hostname"],
["port"],
["path","pathname","paths","pathnames"],
["query","parameters","queries","search"],
["hash","fragment","anchor"]

These only work for the input object, the output object is bound by the parse_url function from php.js.

["scheme","host","user","pass","path","query","fragment"]

Build from string

var build = scheme.build("http://localhost:3000/application/login?user=github");
console.log(build);	

Return

{
  scheme: 'http',
  host: 'localhost',
  port: '3000',
  path: [
    'application',
    'login'
  ],
  query: {
    user: 'github'
  }
}

Nesting

var build = scheme.build({
    "scheme": "https://",
    "domain": "domain.com",
    "path": "/login",
    "query":{
        "user":"thomasreggi",
        "from":scheme.build({
            "scheme": "https://",
            "domain": "redirect.com",
            "path": "/funstuff",
        }),
    }
});
console.log(build);

Return

https://domain.com/login?user=thomasreggi&from=https%3A%2F%2Fredirect.com%2Ffunstuff

Origin

Readme

Keywords

Package Sidebar

Install

npm i scheme

Weekly Downloads

0

Version

0.0.2

License

none

Unpacked Size

6.71 kB

Total Files

5

Last publish

Collaborators

  • reggi