-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added `deno test --doc` * Added `deno fmt --check` * Using double quotes instead of single quotes * Added deno settings to .vscode * Updated function comments
- Loading branch information
Showing
10 changed files
with
101 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"deno.enable": true | ||
} | ||
"deno.enable": true, | ||
"deno.lint": true, | ||
"deno.unstable": false, | ||
"editor.defaultFormatter": "denoland.vscode-deno" | ||
} |
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { getDirname } from './src/get_dirname.ts'; | ||
export { getFilename } from './src/get_filename.ts'; | ||
export { getDirname } from "./src/get_dirname.ts"; | ||
export { getFilename } from "./src/get_filename.ts"; |
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
const removeProtocolAndFilenameRegex = /\w+:\/\/(.*)\/[^/]+$/; | ||
|
||
/** | ||
* Returns the directory of the current module. | ||
* | ||
* ``` ts | ||
* import { getDirname } from './get_dirname.ts'; | ||
* const __dirname = getDirname(import.meta.url); | ||
* | ||
* ``` | ||
*/ | ||
export function getDirname(importMetaUrl: string): string { | ||
return importMetaUrl.replace(removeProtocolAndFilenameRegex, '$1'); | ||
return importMetaUrl.replace(removeProtocolAndFilenameRegex, "$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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
const removeProtocolRegex = /\w+:\/\//; | ||
|
||
/** | ||
* Returns the filename of the current module. | ||
* | ||
* ``` ts | ||
* import { getFilename } from './get_filename.ts'; | ||
* const __filename = getFilename(import.meta.url); | ||
* | ||
* ``` | ||
*/ | ||
export function getFilename(importMetaUrl: string): string { | ||
return importMetaUrl.replace(removeProtocolRegex, ''); | ||
return importMetaUrl.replace(removeProtocolRegex, ""); | ||
} |
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 |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import { assertEquals } from 'https://deno.land/std@0.82.0/testing/asserts.ts'; | ||
import { getDirname } from '../mod.ts'; | ||
import { assertEquals } from "https://deno.land/std@0.82.0/testing/asserts.ts"; | ||
import { getDirname } from "../mod.ts"; | ||
|
||
Deno.test('Get dirname from a simple directory', () => { | ||
Deno.test("Get dirname from a simple directory", () => { | ||
const __dirname = getDirname( | ||
'file:///Users/santiago.aguilar/Desktop/index.ts', | ||
"file:///Users/santiago.aguilar/Desktop/index.ts", | ||
); | ||
|
||
assertEquals(__dirname, '/Users/santiago.aguilar/Desktop'); | ||
assertEquals(__dirname, "/Users/santiago.aguilar/Desktop"); | ||
}); | ||
|
||
Deno.test('Get dirname with a directory with spaces', () => { | ||
Deno.test("Get dirname with a directory with spaces", () => { | ||
const __dirname = getDirname( | ||
'file:///Users/santiago.aguilar/Desktop/dir%20with%20spaces/index.ts', | ||
"file:///Users/santiago.aguilar/Desktop/dir%20with%20spaces/index.ts", | ||
); | ||
|
||
assertEquals( | ||
__dirname, | ||
'/Users/santiago.aguilar/Desktop/dir%20with%20spaces', | ||
"/Users/santiago.aguilar/Desktop/dir%20with%20spaces", | ||
); | ||
}); | ||
|
||
Deno.test('Get dirname with a directory with dots', () => { | ||
Deno.test("Get dirname with a directory with dots", () => { | ||
const __dirname = getDirname( | ||
'file:///Users/santiago.aguilar/Desktop/dir.with.dots/index.ts', | ||
"file:///Users/santiago.aguilar/Desktop/dir.with.dots/index.ts", | ||
); | ||
|
||
assertEquals(__dirname, '/Users/santiago.aguilar/Desktop/dir.with.dots'); | ||
assertEquals(__dirname, "/Users/santiago.aguilar/Desktop/dir.with.dots"); | ||
}); | ||
|
||
Deno.test('Get dirname with a directory with dashes', () => { | ||
Deno.test("Get dirname with a directory with dashes", () => { | ||
const __dirname = getDirname( | ||
'file:///Users/santiago.aguilar/Desktop/dir-with-dashes/index.ts', | ||
"file:///Users/santiago.aguilar/Desktop/dir-with-dashes/index.ts", | ||
); | ||
|
||
assertEquals(__dirname, '/Users/santiago.aguilar/Desktop/dir-with-dashes'); | ||
assertEquals(__dirname, "/Users/santiago.aguilar/Desktop/dir-with-dashes"); | ||
}); | ||
|
||
Deno.test('Get dirname with a file without extension', () => { | ||
const __dirname = getDirname('file:///Users/santiago.aguilar/Desktop/index'); | ||
Deno.test("Get dirname with a file without extension", () => { | ||
const __dirname = getDirname("file:///Users/santiago.aguilar/Desktop/index"); | ||
|
||
assertEquals(__dirname, '/Users/santiago.aguilar/Desktop'); | ||
assertEquals(__dirname, "/Users/santiago.aguilar/Desktop"); | ||
}); | ||
|
||
Deno.test('Get dirname with a hidden file', () => { | ||
const __dirname = getDirname('file:///Users/santiago.aguilar/Desktop/.index'); | ||
Deno.test("Get dirname with a hidden file", () => { | ||
const __dirname = getDirname("file:///Users/santiago.aguilar/Desktop/.index"); | ||
|
||
assertEquals(__dirname, '/Users/santiago.aguilar/Desktop'); | ||
assertEquals(__dirname, "/Users/santiago.aguilar/Desktop"); | ||
}); |
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 |
---|---|---|
@@ -1,59 +1,59 @@ | ||
import { assertEquals } from 'https://deno.land/std@0.82.0/testing/asserts.ts'; | ||
import { getFilename } from '../mod.ts'; | ||
import { assertEquals } from "https://deno.land/std@0.82.0/testing/asserts.ts"; | ||
import { getFilename } from "../mod.ts"; | ||
|
||
Deno.test('Get filename from a simple directory', () => { | ||
Deno.test("Get filename from a simple directory", () => { | ||
const __filename = getFilename( | ||
'file:///Users/santiago.aguilar/Desktop/index.ts', | ||
"file:///Users/santiago.aguilar/Desktop/index.ts", | ||
); | ||
|
||
assertEquals(__filename, '/Users/santiago.aguilar/Desktop/index.ts'); | ||
assertEquals(__filename, "/Users/santiago.aguilar/Desktop/index.ts"); | ||
}); | ||
|
||
Deno.test('Get filename with a directory with spaces', () => { | ||
Deno.test("Get filename with a directory with spaces", () => { | ||
const __filename = getFilename( | ||
'file:///Users/santiago.aguilar/Desktop/dir%20with%20spaces/index.ts', | ||
"file:///Users/santiago.aguilar/Desktop/dir%20with%20spaces/index.ts", | ||
); | ||
|
||
assertEquals( | ||
__filename, | ||
'/Users/santiago.aguilar/Desktop/dir%20with%20spaces/index.ts', | ||
"/Users/santiago.aguilar/Desktop/dir%20with%20spaces/index.ts", | ||
); | ||
}); | ||
|
||
Deno.test('Get filename with a directory with dots', () => { | ||
Deno.test("Get filename with a directory with dots", () => { | ||
const __filename = getFilename( | ||
'file:///Users/santiago.aguilar/Desktop/dir.with.dots/index.ts', | ||
"file:///Users/santiago.aguilar/Desktop/dir.with.dots/index.ts", | ||
); | ||
|
||
assertEquals( | ||
__filename, | ||
'/Users/santiago.aguilar/Desktop/dir.with.dots/index.ts', | ||
"/Users/santiago.aguilar/Desktop/dir.with.dots/index.ts", | ||
); | ||
}); | ||
|
||
Deno.test('Get filename with a directory with dashes', () => { | ||
Deno.test("Get filename with a directory with dashes", () => { | ||
const __filename = getFilename( | ||
'file:///Users/santiago.aguilar/Desktop/dir-with-dashes/index.ts', | ||
"file:///Users/santiago.aguilar/Desktop/dir-with-dashes/index.ts", | ||
); | ||
|
||
assertEquals( | ||
__filename, | ||
'/Users/santiago.aguilar/Desktop/dir-with-dashes/index.ts', | ||
"/Users/santiago.aguilar/Desktop/dir-with-dashes/index.ts", | ||
); | ||
}); | ||
|
||
Deno.test('Get filename without extension', () => { | ||
Deno.test("Get filename without extension", () => { | ||
const __filename = getFilename( | ||
'file:///Users/santiago.aguilar/Desktop/index', | ||
"file:///Users/santiago.aguilar/Desktop/index", | ||
); | ||
|
||
assertEquals(__filename, '/Users/santiago.aguilar/Desktop/index'); | ||
assertEquals(__filename, "/Users/santiago.aguilar/Desktop/index"); | ||
}); | ||
|
||
Deno.test('Get filename in a hidden file', () => { | ||
Deno.test("Get filename in a hidden file", () => { | ||
const __filename = getFilename( | ||
'file:///Users/santiago.aguilar/Desktop/.index', | ||
"file:///Users/santiago.aguilar/Desktop/.index", | ||
); | ||
|
||
assertEquals(__filename, '/Users/santiago.aguilar/Desktop/.index'); | ||
assertEquals(__filename, "/Users/santiago.aguilar/Desktop/.index"); | ||
}); |