-
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.
docs ~ refactor Deno example to reduce code duplication
- Loading branch information
Showing
2 changed files
with
32 additions
and
31 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,36 +1,37 @@ | ||
/* eslint-env es6, deno */ | ||
// # spell-checker:ignore Deno | ||
|
||
/* eslint-disable no-console , security/detect-object-injection, security-node/detect-crlf , @typescript-eslint/ban-ts-comment , @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable no-console , functional/immutable-data , security/detect-object-injection, security-node/detect-crlf , @typescript-eslint/ban-ts-comment , @typescript-eslint/no-explicit-any */ | ||
|
||
// @ts-ignore | ||
import osPaths from 'https://cdn.jsdelivr.net/gh/rivy/js.os-paths@5b6b93bdb048098b86f9b8f0952180c2bf0532b1/src/mod.deno.ts'; | ||
// import osPaths from 'https://cdn.jsdelivr.net/gh/rivy/js.os-paths@5b6b93bdb048098b86f9b8f0952180c2bf0532b1/src/mod.deno.ts'; | ||
// import osPaths from 'https://cdn.jsdelivr.net/gh/rivy/js.os-paths@2d5924e692617a575c8a73c9fb611e93085c4339/src/mod.deno.ts'; | ||
// import osPaths from 'https://cdn.jsdelivr.net/gh/rivy/js.os-paths@latest/src/mod.deno.ts'; | ||
import osPaths from 'https://cdn.jsdelivr.net/gh/rivy/js.os-paths@6.0/src/mod.deno.ts'; | ||
|
||
// create a local reference to refer to `Deno` (for better linting without need for multiple `// @ts-ignore` directives) | ||
// @ts-ignore | ||
const deno = Deno; | ||
|
||
console.log({ osPaths }); | ||
function objectEntries(obj: any) { | ||
const map: any = {}; | ||
Object.keys(obj).forEach((key) => { | ||
const value = obj[key]; | ||
const val = typeof value === 'function' ? value() : value; | ||
map[key] = val; | ||
}); | ||
return map; | ||
} | ||
|
||
Object.keys(osPaths).forEach((key) => { | ||
const value = (osPaths as any)[key](); | ||
console.log({ key, value }); | ||
}); | ||
console.log({ osPaths }); | ||
console.log(objectEntries(osPaths)); | ||
|
||
deno.env.set('TEMP', 'temp'); | ||
deno.env.set('TMPDIR', 'tmpdir'); | ||
deno.env.set('TMP', 'tmp'); | ||
Object.keys(osPaths).forEach((key) => { | ||
const value = (osPaths as any)[key](); | ||
console.log({ key, value }); | ||
}); | ||
console.log(objectEntries(osPaths)); | ||
|
||
deno.env.set('TEMP', 'NEW'); | ||
Object.keys(osPaths).forEach((key) => { | ||
const value = (osPaths as any)[key](); | ||
console.log({ key, value }); | ||
}); | ||
console.log(objectEntries(osPaths)); | ||
|
||
/* eslint-enable no-console , security/detect-object-injection, security-node/detect-crlf , @typescript-eslint/ban-ts-comment , @typescript-eslint/no-explicit-any */ | ||
/* eslint-enable no-console , functional/immutable-data , security/detect-object-injection, security-node/detect-crlf , @typescript-eslint/ban-ts-comment , @typescript-eslint/no-explicit-any */ |