Quark #

Modules #

Quark v1.2.0 Documentation


quark/path #

Class: URL #

URL #

URL Processing Tool Type

For example:

// cwd: file:///var/data
// Prints: file:///var/data/index.js
var uri = new URL('index.js');
console.log(uri.href);
// Prints: http://quarks.cc/index.html?args=0
var uri2 = new URL('[`http://quarks.cc/home/../index.html?args=0`](http://quarks.cc/home/../index.html?args=0)')
console.log(uri2.href);
// Prints: 
// Error: Parse uri error, Illegal URL
new URL('[`http://quarks.cc:`](http://quarks.cc:)').href

url.constructor(path?) #

url.href #

Get the complete URL, including parameters
href: "http://xxxx.xxx:81/v1.1.0/quark/path.js?sasasas&asasasa#sdsdsd"

For example:

// Prints: http://quarks.cc/
console.log(new URL('[`http://quarks.cc/`](http://quarks.cc/)').href);

url.filename #

Get full path name
filename: "/D:/Documents/test.js"

For example:

// Prints: /aaa/bbbb/ccc/test.js
console.log(new URL('[`http://quarks.cc/aaa/bbbb/ccc/test.js`](http://quarks.cc/aaa/bbbb/ccc/test.js)').filename);

url.path #

  • @get path: string /a/b/s/test.html?aaaaa=100

For example:

// Prints: /aaa/bbbb/ccc/test.js?asas=asas
console.log(new URL('[`http://quarks.cc/aaa/bbbb/ccc/test.js?asas=asas`](http://quarks.cc/aaa/bbbb/ccc/test.js?asas=asas)').path);

url.dirname #

Full path dir
dirname: "/D:/Documents"

For example:

// Prints: /aaa/bbbb/ccc
console.log(new URL('[`http://quarks.cc/aaa/bbbb/ccc/test.js`](http://quarks.cc/aaa/bbbb/ccc/test.js)').dirname);

Get url query parameters
search: "?sasasas&asasasa"

For example:

// Prints: ?a=A&b=B
console.log(new URL('[`http://quarks.cc/?a=A&b=B`](http://quarks.cc/?a=A&b=B)').search);

url.hash #

hash: "#sdsdsd"
Get hash parameters

For example:

// Prints: #c=C&d=D
console.log(new URL('[`http://quarks.cc/?a=A&b=B#c=C&d=D`](http://quarks.cc/?a=A&b=B#c=C&d=D)').hash);

url.host #

host: "quarks.cc:81"
Gets the host name and returns the host name with the port number

For example:

// Prints: quarks.cc:80
console.log(new URL('[`http://quarks.cc:81/`](http://quarks.cc:81/)').host);

url.hostname #

hostname: "quarks.cc"
Gets the host name, but does not return the port number

For example:

// Prints: quarks.cc
console.log(new URL('[`http://quarks.cc:81/`](http://quarks.cc:81/)').host);

url.origin #

origin: "http://quarks.cc:81"
Get the uri origin, protocol+host

For example:

// Prints: http://quarks.cc:81
console.log(new URL('[`http://quarks.cc:81/host/index.html`](http://quarks.cc:81/host/index.html)').host);
// Prints: file://
console.log(new URL('file:///var/data/index.html').host);

url.basename #

Get path base name

For example:

// Prints: index.html
console.log(new URL('file:///var/data/index.html').basename);

url.extname #

Get path extname

For example:

// Prints: .html
console.log(new URL('file:///var/data/index.html').extname);

url.port #

port: "81"
Get the host port number.
If the port number is not defined in the URL, an empty string is returned.

For example:

// Prints: 81
console.log(new URL('[`http://quarks.cc:81`](http://quarks.cc:81)').port);
// Prints If there is no port number, an empty string will be returned: ""
console.log(new URL('[`http://quarks.cc`](http://quarks.cc)').port);

url.protocol #

Get the protocol type string of the URL, For: 'http:'|'https'|'ftp:'

url.params #

Returns a collection of query parameters as an object, or set

For example:

// Prints:
// {
//   a: "100",
//   b: "test"
// }
console.log(new URL('[`http://quarks.cc/?a=100&b=test`](http://quarks.cc/?a=100&b=test)').params);

url.hashParams #

Returns a Hash parameter set as an object, or set

  • @get hashParams: Dict<string>

For example:

// Prints:
// {
//   a: "200",
//   b: "300"
// }
console.log(new URL('[`http://quarks.cc/#a=200&b=300`](http://quarks.cc/#a=200&b=300)').hashParams);

url.getParam(name) #

Get path param

For example:

// Prints: ok
console.log(new URL('[`http://quarks.cc/?args=ok`](http://quarks.cc/?args=ok)').getParam('args'));

url.setParam(name,value) #

Set the URL query parameter key-value pair and return self

url.deleteParam(name) #

Remove URL query parameters by name

url.clearParams() #

Delete all of params in the URL

url.getHash(name) #

Get hash param by name

url.setHash(name,value) #

Set hash param by the key/value

url.deleteHash(name) #

Delete hash param by the name

url.clearHashs() #

Delete all of hash params in the URL

url.relative(fromPath) #

Get relative path from the fromPath to self

For example:

// Prints: ../A/B/C/test.js
var url = new URL('[`http://quarks.cc/A/B/C/test.js`](http://quarks.cc/A/B/C/test.js)');
console.log(url.relative('[`http://quarks.cc/home/`](http://quarks.cc/home/)'));
// Prints: file:///var/data/A/B/C/test.js
var url2 = new URL('file:///var/data/A/B/C/test.js');
console.log(url2.relative('[`http://quarks.cc/home/`](http://quarks.cc/home/)'));

url.toJSON() #

default #

default.executable()string #

Get the binary executable file path of the current application

For example:

// Prints:
// file:///var/containers/Bundle/Application/4F1BD659-601D-4932-8484-D0D1F978F0BE/test.app/test
console.log(path.executable());

default.documents(path?) #

Get the document storage path of the current application

  • @param path?: string Append to the document path

For example:

// Prints:
// file:///var/mobile/Containers/Data/Application/89A576FE-7BB9-4F26-A456-E9D7F8AD053D/Documents
console.log(path.documents());
// Prints Setting the result of appending path parameters:
// file:///var/mobile/Containers/Data/Application/89A576FE-7BB9-4F26-A456-E9D7F8AD053D/Documents/aa.jpeg
console.log(path.documents('aa.jpeg'));

default.temp(path?) #

Get the application temporary directory

default.resources(path?) #

Get the application resource directory

default.cwd()string #

Get the current working directory

default.chdir(path) #

Set the current working directory and return true if successful

default.normalizePath(path,retain_up?) #

Format part path to normalize path

default.classicPath(path) #

Restore the path to a path that the operating system can recognize.
Generally, you do not need to call this function unless you directly call
a Native/C/C++ function that is not provided by Quark

For example:

// Prints: /var/data/test.js
console.log(path.normalizePath('file:///var/data/test.js'));

default.resolve(path,partPath?string) #

Format path to standard absolute path

For example:

// Prints: http://quarks.cc/A/C/test.js
console.log(path.resolve('[`http://quarks.cc/home`](http://quarks.cc/home)', "..", "A", "B", "..", "C", "test.js"));
// Prints: 
// true
// file:///var/data/aaa/cc/ddd/kk.jpg
console.log(path.chdir('/var/data'));
console.log(path.resolve('aaa/bbb/../cc/.//!<ddd/kk.jpg'));
  • @param path: string
  • @param partPath?string:
  • @return string

default.isAbsolute(path) #

Test whether it is an absolute path

For example:

// Prints:
// true
// true
// false
console.log(path.isAbsolute('/var/kk'));
console.log(path.isAbsolute('[`http://quarks.cc/`](http://quarks.cc/)'));
console.log(path.isAbsolute('index.jsx'));

default.basename(path?) #

Get basename

default.dirname(path?) #

Get dirname

default.extname(path?) #

Get extname

default.filename(path?) #

Get filename

default.path(path?) #

Get path

default.search(path?) #

Get search

default.hash(path?) #

Get hash

default.host(path?) #

Get host

default.hostname(path?) #

Get hostname

default.origin(path?) #

Get origin

default.port(path?) #

Get port: "81"

default.protocol(path?) #

Get protocol: "http:"

default.params(path?) #

Get params

default.hashParams(path?) #

Get params

default.getParam(name,path?) #

Get path param

default.setParam(name,value,path?) #

Set path param

default.deleteParam(name,path?) #

Delete path param

default.clearParams(path?) #

Delete all of hash params

default.getHash(name,path?) #

Get hash param

default.setHash(name,value,path?) #

Set hash param

default.deleteHash(name,path?) #

Delete hash param

default.clearHashs(path?) #

Delete all of hash params

default.relative(from,target?) #

Get relative path