diff --git a/mod.full.ts b/mod.full.ts index a7ac2ad..20cdae6 100644 --- a/mod.full.ts +++ b/mod.full.ts @@ -1,8 +1,9 @@ -export * from "./mod.ts"; +export * from "./mod.pure.full.ts"; -export * from "./src/pure_ext/csv.ts"; -export * from "./src/pure_ext/excel.ts"; -export * from "./src/pure_ext/zip.ts"; +export * from "./src/deno/json.ts"; +export * from "./src/deno/os.ts"; +export * from "./src/deno/path.ts"; +export * from "./src/deno/process.ts"; export * from "./src/deno_ext/dom.ts"; export * from "./src/deno_ext/log.ts"; diff --git a/mod.test.ts b/mod.test.ts index 1643eb5..5c42a63 100644 --- a/mod.test.ts +++ b/mod.test.ts @@ -5,6 +5,7 @@ import "./test/pure/deep.test.ts"; import "./test/pure/deflate.test.ts"; import "./test/pure/fetch.test.ts"; import "./test/pure/minipack.test.ts"; +import "./test/deno/os.test.ts"; import "./test/pure/primitive.test.ts"; import "./test/pure/stream.test.ts"; import "./test/pure/text.test.ts"; @@ -16,7 +17,6 @@ import "./test/pure_ext/excel.test.ts"; import "./test/pure_ext/zip.test.ts"; import "./test/deno/json.test.ts"; -import "./test/deno/os.test.ts"; import "./test/deno/path.test.ts"; import "./test/deno/process.test.ts"; diff --git a/mod.ts b/mod.ts index 42867e6..985afb1 100644 --- a/mod.ts +++ b/mod.ts @@ -1,15 +1,4 @@ -export * from "./src/pure/base64.ts"; -export * from "./src/pure/byte.ts"; -export * from "./src/pure/crypto.ts"; -export * from "./src/pure/deep.ts"; -export * from "./src/pure/deflate.ts"; -export * from "./src/pure/fetch.ts"; -export * from "./src/pure/minipack.ts"; -export * from "./src/pure/primitive.ts"; -export * from "./src/pure/stream.ts"; -export * from "./src/pure/text.ts"; -export * from "./src/pure/time.ts"; -export * from "./src/pure/worker.ts"; +export * from "./mod.pure.ts"; export * from "./src/deno/json.ts"; export * from "./src/deno/os.ts"; diff --git a/src/deno/os.ts b/src/deno/os.ts index eb05228..8880214 100644 --- a/src/deno/os.ts +++ b/src/deno/os.ts @@ -5,4 +5,22 @@ * const isWin = osWin; * ``` */ -export const osWin:boolean = Deno.build.os === "windows"; \ No newline at end of file +export const osWindows:boolean = Deno.build.os === "windows"; + +/** +* Are you running on Mac? +* @example +* ```ts +* const isWin = osMac; +* ``` +*/ +export const osMac:boolean = Deno.build.os === "darwin"; + +/** +* Are you running on Linux? +* @example +* ```ts +* const isWin = osLinux; +* ``` +*/ +export const osLinux:boolean = Deno.build.os === "linux"; \ No newline at end of file diff --git a/src/deno/path.ts b/src/deno/path.ts index 696b86a..b4b18d2 100644 --- a/src/deno/path.ts +++ b/src/deno/path.ts @@ -1,14 +1,14 @@ -import {osWin} from "./os.ts"; +import {osWindows} from "./os.ts"; /** * Convert from backslash to slash. * Useful for converting from Windows path to UNIX path. * @example * ```ts -* const path = slashU("C:\\file"); +* const path = pathSepL("C:\\file"); * ``` */ -export function slashU(path:string):string{ +export function pathSepL(path:string):string{ return path.replace(/\\/g, "/"); } @@ -17,10 +17,10 @@ export function slashU(path:string):string{ * Useful for converting from UNIX path to Windows path. * @example * ```ts -* const path = slashW("C:/file"); +* const path = pathSepW("C:/file"); * ``` */ -export function slashW(path:string):string{ +export function pathSepW(path:string):string{ return path.replace(/\//g, "\\"); } @@ -29,11 +29,11 @@ export function slashW(path:string):string{ * `/tmp` for UNIX and `C:/Windows/Temp` for Windows. * @example * ```ts -* const path = tmpPath(); +* const path = pathTmp(); * ``` */ -export function tmpPath():string{ - return osWin ? "C:/Windows/Temp" : "/tmp"; +export function pathTmp():string{ + return osWindows ? "C:/Windows/Temp" : "/tmp"; } /** @@ -41,11 +41,11 @@ export function tmpPath():string{ * `/var` for UNIX and `C:/ProgramData` for Windows. * @example * ```ts -* const path = dataPath(); +* const path = pathVar(); * ``` */ -export function dataPath():string{ - return osWin ? "C:/ProgramData" : "/var"; +export function pathVar():string{ + return osWindows ? "C:/ProgramData" : "/var"; } /** @@ -53,11 +53,11 @@ export function dataPath():string{ * `~/.config` for UNIX and `~/AppData/Roaming` for Windows. * @example * ```ts -* const path = configPath(); +* const path = pathConfig(); * ``` */ -export function configPath():string{ - return `${homePath()}/${osWin ? "AppData/Roaming" : ".config"}`; +export function pathConfig():string{ + return `${pathHome()}/${osWindows ? "AppData/Roaming" : ".config"}`; } /** @@ -65,25 +65,24 @@ export function configPath():string{ * `${HOME}` for UNIX and `%USERPROFILE%` for Windows. * @example * ```ts -* const path = homePath(); +* const path = pathHome(); * ``` */ -export function homePath():string{ +export function pathHome():string{ const {HOME, USERPROFILE} = Deno.env.toObject(); - return osWin ? slashU(USERPROFILE) : HOME; + return osWindows ? pathSepL(USERPROFILE) : HOME; } /** * Directory of `Deno.mainModule`. * @example * ```ts -* const path = mainPath(); +* const path = pathMain(); * ``` */ -export function mainPath():string{ - const {protocol, origin, pathname} = new URL(Deno.mainModule); - const path = pathname.replace(/[^/]*$/, ""); +export function pathMain():string{ + const directory = new URL(Deno.mainModule).pathname.replace(/[^/]*$/, ""); - return protocol === "file:" ? osWin ? path.replace(/^\//, "") : path : `${origin}${path}`; + return osWindows ? directory.replace(/^\//, "") : directory; } \ No newline at end of file diff --git a/test/deno/os.test.ts b/test/deno/os.test.ts index d93f8b6..4987c16 100644 --- a/test/deno/os.test.ts +++ b/test/deno/os.test.ts @@ -1,18 +1,32 @@ import {assertEquals} from "../../deps.test.ts"; -import {osWin} from "../../src/deno/os.ts"; +import {osWindows, osMac, osLinux} from "../../src/deno/os.ts"; Deno.test({ - ignore: Deno.build.os !== "windows", - name: "Platform: Windows", + ignore: Deno.build.os === "windows", + name: "OS: Windows", fn(){ - assertEquals(osWin, true); + assertEquals(osWindows, true); + assertEquals(osMac, false); + assertEquals(osLinux, false); } }); Deno.test({ - ignore: Deno.build.os === "windows", - name: "Platform: Unix", + ignore: Deno.build.os === "darwin", + name: "OS: Mac", + fn(){ + assertEquals(osWindows, false); + assertEquals(osMac, true); + assertEquals(osLinux, false); + } +}); + +Deno.test({ + ignore: Deno.build.os === "linux", + name: "OS: Linux", fn(){ - assertEquals(osWin, false); + assertEquals(osWindows, false); + assertEquals(osMac, false); + assertEquals(osLinux, true); } }); \ No newline at end of file diff --git a/test/deno/path.test.ts b/test/deno/path.test.ts index e8399ee..12c6892 100644 --- a/test/deno/path.test.ts +++ b/test/deno/path.test.ts @@ -1,5 +1,5 @@ import {assertEquals, dirname, fromFileUrl} from "../../deps.test.ts"; -import {slashU, slashW, tmpPath, dataPath, configPath, homePath, mainPath} from "../../src/deno/path.ts"; +import {pathSepL, pathSepW, pathTmp, pathVar, pathConfig, pathHome, pathMain} from "../../src/deno/path.ts"; const {HOME, USERPROFILE} = Deno.env.toObject(); const ep = `${fromFileUrl(dirname(Deno.mainModule))}/`; @@ -10,8 +10,8 @@ Deno.test({ const sampleUnix = "C:/Windows/System32/cmd.exe"; const sampleWindows = "C:\\Windows\\System32\\cmd.exe"; - assertEquals(slashU(sampleWindows), sampleUnix); - assertEquals(slashW(sampleUnix), sampleWindows); + assertEquals(pathSepL(sampleWindows), sampleUnix); + assertEquals(pathSepW(sampleUnix), sampleWindows); } }); @@ -19,11 +19,11 @@ Deno.test({ ignore: Deno.build.os !== "windows", name: "Path: Windows", fn(){ - assertEquals(tmpPath(), "C:/Windows/Temp"); - assertEquals(dataPath(), "C:/ProgramData"); - assertEquals(configPath(), `${slashU(USERPROFILE)}/AppData/Roaming`); - assertEquals(homePath(), slashU(USERPROFILE)); - assertEquals(mainPath(), slashU(ep)); + assertEquals(pathTmp(), "C:/Windows/Temp"); + assertEquals(pathVar(), "C:/ProgramData"); + assertEquals(pathConfig(), `${pathSepL(USERPROFILE)}/AppData/Roaming`); + assertEquals(pathHome(), pathSepL(USERPROFILE)); + assertEquals(pathMain(), pathSepL(ep)); } }); @@ -31,10 +31,10 @@ Deno.test({ ignore: Deno.build.os === "windows", name: "Path: Unix", fn(){ - assertEquals(tmpPath(), "/tmp"); - assertEquals(dataPath(), "/var"); - assertEquals(configPath(), `${HOME}/.config`); - assertEquals(homePath(), HOME); - assertEquals(mainPath(), ep); + assertEquals(pathTmp(), "/tmp"); + assertEquals(pathVar(), "/var"); + assertEquals(pathConfig(), `${HOME}/.config`); + assertEquals(pathHome(), HOME); + assertEquals(pathMain(), ep); } }); \ No newline at end of file