ngui/url
獲取當(dāng)前應(yīng)用程序的二進(jìn)制執(zhí)行文件路徑
String
}Example:
// Prints:
// file:///var/containers/Bundle/Application/4F1BD659-601D-4932-8484-D0D1F978F0BE/test.app/test
console.log(url.executable());
獲取當(dāng)前應(yīng)用程序的文檔存儲(chǔ)路徑
Example:
// Prints:
// file:///var/mobile/Containers/Data/Application/89A576FE-7BB9-4F26-A456-E9D7F8AD053D/Documents
console.log(url.documents());
// Prints 設(shè)置追加路徑參數(shù)的結(jié)果:
// file:///var/mobile/Containers/Data/Application/89A576FE-7BB9-4F26-A456-E9D7F8AD053D/Documents/aa.jpeg
console.log(url.documents('aa.jpeg'));
獲取應(yīng)用程序臨時(shí)目錄
獲取應(yīng)用程序資源目錄
恢復(fù)路徑為操作系統(tǒng)可以識(shí)別的路徑,一般不需要使用該函數(shù),除非直接調(diào)用非NGUI
提供的Native/C/C++函數(shù)
Example:
// Prints: /var/data/test.js
console.log(url.fallback('file:///var/data/test.js'));
獲取當(dāng)前工作目錄
String
}
設(shè)置當(dāng)前工作目錄,成功后返回true
測(cè)試路徑是否為一個(gè)絕對(duì)路徑
Example:
// Prints:
// true
// true
// false
console.log(url.isAbsolute('/var/kk'));
console.log(url.isAbsolute('http://nodegui.org/'));
console.log(url.isAbsolute('index.jsx'));
格式化傳入的路徑為標(biāo)準(zhǔn)絕對(duì)路徑
Example:
// Prints: http://nodegui.org/A/C/test.js
console.log(url.resolve('http://nodegui.org/home', "..", "A", "B", "..", "C", "test.js"));
// Prints:
// true
// file:///var/data/aaa/cc/ddd/kk.jpg
console.log(url.chdir('/var/data'));
console.log(url.resolve('aaa/bbb/../cc/.///ddd/kk.jpg'));
Class: URL
url與path處理類(lèi)
構(gòu)造函數(shù),如果傳入非法路徑會(huì)拋出異常
[path='']
{String
} 字符串路徑,傳入相對(duì)路徑或決對(duì)路徑Example:
// cwd: file:///var/data
// Prints: file:///var/data/index.js
var uri = new URL('index.js');
console.log(uri.href);
// Prints: http://nodegui.org/index.html?args=0
var uri2 = new URL('http://nodegui.org/home/../index.html?args=0')
console.log(uri2.href);
// Prints:
// Error: Parse uri error, Illegal URL
new URL('http://nodegui.org:').href
獲取uri完整的href,包括參數(shù)
String
}Example:
// Prints: http://nodegui.org/
console.log(new URL('http://nodegui.org/').href);
獲取文件名稱(chēng)
String
}// Prints: /aaa/bbbb/ccc/test.js
console.log(new URL('http://nodegui.org/aaa/bbbb/ccc/test.js').filename);
獲取目錄名稱(chēng)
Example:
// Prints: /aaa/bbbb/ccc
console.log(new URL('http://nodegui.org/aaa/bbbb/ccc/test.js').dirname);
獲取uri查詢(xún)參數(shù)
String
}Example:
// Prints: ?a=A&b=B
console.log(new URL('http://nodegui.org/?a=A&b=B').search);
獲取hash參數(shù)
String
}Example:
// Prints: #c=C&d=D
console.log(new URL('http://nodegui.org/?a=A&b=B#c=C&d=D').hash);
獲取主機(jī),返回一個(gè)帶端口號(hào)的主機(jī)名稱(chēng)
String
}Example:
// Prints: nodegui.org:80
console.log(new URL('http://nodegui.org:81/').host);
獲取主機(jī)名稱(chēng),不會(huì)返回端口號(hào)
String
}Example:
// Prints: nodegui.org
console.log(new URL('http://nodegui.org:81/').host);
獲取uri起源,protocol+host
String
}Example:
// Prints: http://nodegui.org:81
console.log(new URL('http://nodegui.org:81/host/index.html').host);
// Prints: file://
console.log(new URL('file:///var/data/index.html').host);
獲取基礎(chǔ)文件名稱(chēng)
String
}Example:
// Prints: index.html
console.log(new URL('file:///var/data/index.html').basename);
獲取文件擴(kuò)展名稱(chēng)
String
}Example:
// Prints: .html
console.log(new URL('file:///var/data/index.html').extname);
獲取主機(jī)端口號(hào),如果URL中沒(méi)有定義端口號(hào)返回一個(gè)空字符串
Example:
String
}// Prints: 81
console.log(new URL('http://nodegui.org:81').port);
// Prints 沒(méi)有端口號(hào)會(huì)返回空字符串: ""
console.log(new URL('http://nodegui.org').port);
獲取URL的協(xié)議類(lèi)型字符串, 例如: 'http:'
|'https'
|'ftp:'
以對(duì)像方式返回查詢(xún)參數(shù)集合
String
}Example:
// Prints:
// {
// a: "100",
// b: "test"
// }
console.log(new URL('http://nodegui.org/?a=100&b=test').params);
以對(duì)像方式返回Hash參數(shù)集合
Object
}Example:
// Prints:
// {
// a: "200",
// b: "300"
// }
console.log(new URL('http://nodegui.org/#a=200&b=300').hashParams);
通過(guò)名稱(chēng)獲取uri參數(shù)值
Example:
// Prints: ok
console.log(new URL('http://nodegui.org/?args=ok').getParam('args'));
設(shè)置URL查詢(xún)參數(shù)鍵值對(duì),并返回自己
通過(guò)名稱(chēng)刪除URL查詢(xún)參數(shù)
name
{String
}刪除URL中的所有查詢(xún)參數(shù)
返回與target
的相對(duì)路徑
Example:
// Prints: ../A/B/C/test.js
var uri = new URL('http://nodegui.org/home/');
console.log(uri.relative('http://nodegui.org/A/B/C/test.js'));
// Prints: file:///var/data/A/B/C/test.js
var uri2 = new URL('http://nodegui.org/home/');
console.log(uri2.relative('file:///var/data/A/B/C/test.js'));
下面為URL快捷函數(shù),其中第一個(gè)參數(shù)都為創(chuàng)建URL對(duì)像用到的路徑
更多建議: