Skip to content

URI constructor does not take an object as value for query property #366

Closed
@wachunei

Description

@wachunei

Hello everyone,

Please let me know if this is this has been decided to be like this or not, but when building an URL, query property only takes a string as value, instead of search() or query() that take both string and objects.

Heres an example code (online repl here):

const assert = require('assert');
const URI = require('urijs');

const PROTOCOL = 'http';
const HOST = 'mycustom.domain.com';
const PORT = '443';
const BASE_PATH = '/some//path/';
const resource = '///resource//5';
const query = {
  myQuery: 'rocks'
}

const constructorURI = new URI({
    protocol: PROTOCOL,
    hostname: HOST,
    port: PORT,
    path: `${BASE_PATH}/${resource}/`,
    query,
  }).normalize();
  
  
const searchURI = new URI({
    protocol: PROTOCOL,
    hostname: HOST,
    port: PORT,
    path: `${BASE_PATH}/${resource}/`,
  }).search(query).normalize();

assert(constructorURI.toString() === searchURI.toString(), 'URIs are not equal');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions