Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2 using ES5 properties? #56

Open
nathanboktae opened this issue Sep 11, 2015 · 0 comments
Open

v2 using ES5 properties? #56

nathanboktae opened this issue Sep 11, 2015 · 0 comments

Comments

@nathanboktae
Copy link

Have you considered freshening up the API with ES5 Properties? I'll take the readme and offer a proposal of what could be done with it:


Pass any URL into the constructor:

var uri = new Uri('http://user:pass@www.test.com:81/index.html?q=books#fragment')

Use property methods to get at the various parts:

uri.protocol    // http
uri.userInfo    // user:pass
uri.host        // www.test.com
uri.port        // 81
uri.path        // /index.html
uri.query       // q=books
uri.anchor      // fragment

Property methods accept an optional value to set:

uri.protocol = 'https'
uri.toString()    // https://user:pass@www.test.com:81/index.html?q=books#fragment

uri.host = 'mydomain.com'
uri.toString()    // https://user:pass@mydomain.com:81/index.html?q=books#fragment

ES5 Propery setter methods help you compose strings:

Object.assign(new Uri(), {
    path: '/archives/1979/',
    query: { page: 1 }
}).toString()                   // /archives/1979?page=1

Object.assign(new Uri(), {
    path: '/index.html',
    anchor: 'content',
    host: 'www.test.com',
    port: 8080,
    userInfo: 'username:password',
    protocol: 'https'
    query: {
        this: 'that',
        some: 'thing'
    }
}).toString()                  // https://username:password@www.test.com:8080/index.html?this=that&some=thing#content

especially with the query changes, that would really freshen up the API. Poor souls that still need to support IE8 can stay on v1.

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant