-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -412,6 +412,7 @@ | |
"template", | ||
"throttle", | ||
"through", | ||
"tildify", | ||
"timeAgo", | ||
"times", | ||
"timeTaken", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## CN | ||
|
||
将绝对路径转换为波浪线路径。 | ||
|
||
|参数名|说明| | ||
|-----|---| | ||
|path|要转换的路径| | ||
|返回值|波浪线路径| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* Convert absolute path to tilde path. | ||
* | ||
* |Name |Desc | | ||
* |------|---------------| | ||
* |path |Path to convert| | ||
* |return|Tilde path | | ||
*/ | ||
|
||
/* example | ||
* tildify('/home/surunzi/dev'); // -> '~/dev' | ||
*/ | ||
|
||
/* module | ||
* env: node | ||
*/ | ||
|
||
/* typescript | ||
* export declare function tildify(path: string): string; | ||
*/ | ||
|
||
_('startWith'); | ||
|
||
const path = require('path'); | ||
const os = require('os'); | ||
|
||
const homeDir = os.homedir(); | ||
|
||
exports = function(p) { | ||
p = path.normalize(p) + path.sep; | ||
if (startWith(p, homeDir)) { | ||
p = p.replace(homeDir + path.sep, `~${path.sep}`); | ||
} | ||
|
||
return p.slice(0, -1); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const os = require('os'); | ||
const homeDir = os.homedir(); | ||
|
||
const isWindows = util.isWindows; | ||
|
||
it('basic', function() { | ||
if (isWindows) { | ||
expect(tildify(homeDir + '\\dev')).to.equal('~\\dev'); | ||
} else { | ||
expect(tildify(homeDir + '/dev')).to.equal('~/dev'); | ||
expect(tildify('/usr/dev')).to.equal('/usr/dev'); | ||
} | ||
}); |