@davidsouther/jiffies 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{build → lib/cjs}/assert.d.ts +23 -23
- package/lib/cjs/assert.js +40 -0
- package/{build → lib/cjs}/case.d.ts +1 -1
- package/lib/cjs/case.js +9 -0
- package/{build → lib/cjs}/components/button_bar.d.ts +8 -8
- package/lib/cjs/components/button_bar.js +29 -0
- package/{build → lib/cjs}/components/inline_edit.d.ts +12 -12
- package/lib/cjs/components/inline_edit.js +51 -0
- package/{build → lib/cjs}/components/logger.d.ts +6 -6
- package/lib/cjs/components/logger.js +27 -0
- package/lib/cjs/components/select.d.ts +10 -0
- package/lib/cjs/components/select.js +6 -0
- package/lib/cjs/components/test.d.ts +1 -0
- package/lib/cjs/components/test.js +7 -0
- package/{build → lib/cjs}/components/virtual_scroll.d.ts +40 -40
- package/lib/cjs/components/virtual_scroll.js +102 -0
- package/{build → lib/cjs}/components/virtual_scroll.test.d.ts +1 -1
- package/lib/cjs/components/virtual_scroll.test.js +22 -0
- package/{build → lib/cjs}/context.d.ts +15 -15
- package/lib/cjs/context.js +48 -0
- package/{build → lib/cjs}/context.test.d.ts +1 -1
- package/lib/cjs/context.test.js +48 -0
- package/{build → lib/cjs}/debounce.d.ts +1 -1
- package/lib/cjs/debounce.js +11 -0
- package/lib/cjs/diff.d.ts +15 -0
- package/lib/cjs/diff.js +58 -0
- package/{build/components/test.d.ts → lib/cjs/diff.test.d.ts} +1 -1
- package/lib/cjs/diff.test.js +41 -0
- package/{build → lib/cjs}/display.d.ts +5 -5
- package/lib/cjs/display.js +16 -0
- package/{build → lib/cjs}/dom/css/border.d.ts +11 -11
- package/lib/cjs/dom/css/border.js +33 -0
- package/{build → lib/cjs}/dom/css/constants.d.ts +31 -31
- package/lib/cjs/dom/css/constants.js +31 -0
- package/{build → lib/cjs}/dom/css/core.d.ts +5 -5
- package/lib/cjs/dom/css/core.js +31 -0
- package/{build → lib/cjs}/dom/css/fstyle.d.ts +5 -5
- package/lib/cjs/dom/css/fstyle.js +36 -0
- package/{build → lib/cjs}/dom/css/sizing.d.ts +5 -5
- package/lib/cjs/dom/css/sizing.js +14 -0
- package/{build → lib/cjs}/dom/dom.d.ts +27 -26
- package/lib/cjs/dom/dom.js +110 -0
- package/{build → lib/cjs}/dom/fc.d.ts +14 -14
- package/lib/cjs/dom/fc.js +39 -0
- package/{build → lib/cjs}/dom/fc.test.d.ts +1 -1
- package/lib/cjs/dom/fc.test.js +23 -0
- package/{build → lib/cjs}/dom/form/form.app.d.ts +1 -1
- package/lib/cjs/dom/form/form.app.js +27 -0
- package/{build → lib/cjs}/dom/form/form.d.ts +26 -26
- package/lib/cjs/dom/form/form.js +49 -0
- package/{build → lib/cjs}/dom/form/form.test.d.ts +0 -0
- package/{build → lib/cjs}/dom/form/form.test.js +1 -1
- package/{build → lib/cjs}/dom/html.d.ts +113 -113
- package/lib/cjs/dom/html.js +119 -0
- package/{build → lib/cjs}/dom/html.test.d.ts +1 -1
- package/lib/cjs/dom/html.test.js +60 -0
- package/lib/cjs/dom/observable.d.ts +2 -0
- package/lib/cjs/dom/observable.js +10 -0
- package/{build/observable → lib/cjs/dom}/observable.test.d.ts +1 -1
- package/lib/cjs/dom/observable.test.js +35 -0
- package/{build → lib/cjs}/dom/provide.d.ts +3 -3
- package/lib/cjs/dom/provide.js +12 -0
- package/{build → lib/cjs}/dom/router/link.d.ts +6 -6
- package/lib/cjs/dom/router/link.js +7 -0
- package/{build → lib/cjs}/dom/router/router.d.ts +12 -12
- package/lib/cjs/dom/router/router.js +52 -0
- package/{build → lib/cjs}/dom/svg.d.ts +64 -64
- package/lib/cjs/dom/svg.js +69 -0
- package/lib/cjs/dom/test.d.ts +1 -0
- package/lib/cjs/dom/test.js +13 -0
- package/{build → lib/cjs}/dom/types/css.d.ts +6612 -6612
- package/lib/cjs/dom/types/css.js +24 -0
- package/{build → lib/cjs}/dom/types/dom.d.ts +0 -0
- package/{build → lib/cjs}/dom/types/dom.js +1 -1
- package/{build → lib/cjs}/dom/types/html.d.ts +616 -616
- package/lib/cjs/dom/types/html.js +2 -0
- package/{build → lib/cjs}/dom/xml.d.ts +1 -1
- package/lib/cjs/dom/xml.js +8 -0
- package/{build → lib/cjs}/equal.d.ts +5 -5
- package/lib/cjs/equal.js +43 -0
- package/{build → lib/cjs}/equal.test.d.ts +1 -1
- package/lib/cjs/equal.test.js +22 -0
- package/{build → lib/cjs}/flags.d.ts +7 -7
- package/lib/cjs/flags.js +52 -0
- package/{build → lib/cjs}/flags.test.d.ts +1 -1
- package/lib/cjs/flags.test.js +37 -0
- package/{build → lib/cjs}/fs.d.ts +48 -48
- package/lib/cjs/fs.js +151 -0
- package/{build → lib/cjs}/fs.test.d.ts +1 -1
- package/lib/cjs/fs.test.js +45 -0
- package/{build → lib/cjs}/generator.d.ts +1 -1
- package/lib/cjs/generator.js +14 -0
- package/{build → lib/cjs}/generator.test.d.ts +1 -1
- package/lib/cjs/generator.test.js +26 -0
- package/{build → lib/cjs}/is_browser.d.ts +1 -1
- package/lib/cjs/is_browser.js +4 -0
- package/{build → lib/cjs}/loader.d.mts +22 -22
- package/lib/cjs/loader.mjs +40 -0
- package/{build → lib/cjs}/lock.d.ts +1 -1
- package/lib/cjs/lock.js +27 -0
- package/{build → lib/cjs}/lock.test.d.ts +1 -1
- package/lib/cjs/lock.test.js +18 -0
- package/{build → lib/cjs}/log.d.ts +26 -26
- package/lib/cjs/log.js +54 -0
- package/lib/cjs/observable/event.d.ts +35 -0
- package/lib/cjs/observable/event.js +61 -0
- package/lib/cjs/observable/observable.d.ts +132 -0
- package/lib/cjs/observable/observable.js +363 -0
- package/lib/cjs/observable/observable.test.d.ts +1 -0
- package/lib/cjs/observable/observable.test.js +65 -0
- package/{build → lib/cjs}/range.d.ts +1 -1
- package/lib/cjs/range.js +11 -0
- package/{build → lib/cjs}/result.d.ts +31 -31
- package/lib/cjs/result.js +80 -0
- package/{build → lib/cjs}/result.test.d.ts +1 -1
- package/lib/cjs/result.test.js +73 -0
- package/{build → lib/cjs}/safe.d.ts +1 -1
- package/lib/cjs/safe.js +14 -0
- package/{build → lib/cjs}/scope/describe.d.ts +18 -18
- package/lib/cjs/scope/describe.js +73 -0
- package/{build → lib/cjs}/scope/display/console.d.ts +2 -2
- package/lib/cjs/scope/display/console.js +25 -0
- package/{build → lib/cjs}/scope/display/dom.d.ts +3 -3
- package/lib/cjs/scope/display/dom.js +30 -0
- package/{build → lib/cjs}/scope/display/junit.d.ts +2 -2
- package/lib/cjs/scope/display/junit.js +21 -0
- package/{build → lib/cjs}/scope/execute.d.ts +12 -12
- package/lib/cjs/scope/execute.js +91 -0
- package/{build → lib/cjs}/scope/expect.d.ts +23 -23
- package/lib/cjs/scope/expect.js +114 -0
- package/{build → lib/cjs}/scope/fix.d.ts +4 -4
- package/lib/cjs/scope/fix.js +26 -0
- package/{build → lib/cjs}/scope/index.d.ts +3 -3
- package/lib/cjs/scope/index.js +15 -0
- package/{build → lib/cjs}/scope/scope.d.ts +17 -17
- package/lib/cjs/scope/scope.js +2 -0
- package/lib/cjs/scope/state.d.ts +1 -0
- package/lib/cjs/scope/state.js +11 -0
- package/{build → lib/cjs}/server/http/apps.d.ts +5 -5
- package/lib/cjs/server/http/apps.js +27 -0
- package/{build → lib/cjs}/server/http/css.d.ts +5 -5
- package/lib/cjs/server/http/css.js +54 -0
- package/{build → lib/cjs}/server/http/index.d.ts +21 -21
- package/lib/cjs/server/http/index.js +77 -0
- package/{build → lib/cjs}/server/http/response.d.ts +4 -4
- package/lib/cjs/server/http/response.js +45 -0
- package/{build → lib/cjs}/server/http/sitemap.d.ts +2 -2
- package/lib/cjs/server/http/sitemap.js +46 -0
- package/{build → lib/cjs}/server/http/static.d.ts +2 -2
- package/lib/cjs/server/http/static.js +25 -0
- package/{build → lib/cjs}/server/http/typescript.d.ts +5 -5
- package/lib/cjs/server/http/typescript.js +44 -0
- package/{build → lib/cjs}/server/main.d.ts +2 -2
- package/lib/cjs/server/main.js +14 -0
- package/{build → lib/cjs}/test.d.mts +2 -2
- package/lib/cjs/test.mjs +28 -0
- package/{build → lib/cjs}/test_all.d.ts +9 -7
- package/lib/cjs/test_all.js +30 -0
- package/{build → lib/cjs}/transpile.d.mts +3 -3
- package/lib/cjs/transpile.mjs +22 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -0
- package/lib/esm/assert.d.ts +23 -0
- package/{build → lib/esm}/assert.js +33 -33
- package/lib/esm/case.d.ts +1 -0
- package/{build → lib/esm}/case.js +5 -5
- package/lib/esm/components/button_bar.d.ts +8 -0
- package/{build → lib/esm}/components/button_bar.js +27 -27
- package/lib/esm/components/inline_edit.d.ts +12 -0
- package/{build → lib/esm}/components/inline_edit.js +48 -48
- package/lib/esm/components/logger.d.ts +6 -0
- package/{build → lib/esm}/components/logger.js +22 -22
- package/lib/esm/components/select.d.ts +10 -0
- package/{build → lib/esm}/components/select.js +3 -3
- package/lib/esm/components/test.d.ts +1 -0
- package/lib/esm/components/test.js +3 -0
- package/lib/esm/components/virtual_scroll.d.ts +40 -0
- package/{build → lib/esm}/components/virtual_scroll.js +94 -94
- package/lib/esm/components/virtual_scroll.test.d.ts +1 -0
- package/{build → lib/esm}/components/virtual_scroll.test.js +20 -21
- package/lib/esm/context.d.ts +15 -0
- package/{build → lib/esm}/context.js +43 -43
- package/lib/esm/context.test.d.ts +1 -0
- package/{build → lib/esm}/context.test.js +46 -46
- package/lib/esm/debounce.d.ts +1 -0
- package/{build → lib/esm}/debounce.js +7 -7
- package/lib/esm/diff.d.ts +15 -0
- package/lib/esm/diff.js +54 -0
- package/lib/esm/diff.test.d.ts +1 -0
- package/lib/esm/diff.test.js +39 -0
- package/lib/esm/display.d.ts +5 -0
- package/{build → lib/esm}/display.js +11 -11
- package/lib/esm/dom/css/border.d.ts +11 -0
- package/{build → lib/esm}/dom/css/border.js +27 -27
- package/lib/esm/dom/css/constants.d.ts +31 -0
- package/{build → lib/esm}/dom/css/constants.js +28 -28
- package/lib/esm/dom/css/core.d.ts +5 -0
- package/{build → lib/esm}/dom/css/core.js +24 -24
- package/lib/esm/dom/css/fstyle.d.ts +5 -0
- package/{build → lib/esm}/dom/css/fstyle.js +32 -32
- package/lib/esm/dom/css/sizing.d.ts +5 -0
- package/{build → lib/esm}/dom/css/sizing.js +10 -10
- package/lib/esm/dom/dom.d.ts +27 -0
- package/{build → lib/esm}/dom/dom.js +104 -95
- package/lib/esm/dom/fc.d.ts +14 -0
- package/{build → lib/esm}/dom/fc.js +35 -36
- package/lib/esm/dom/fc.test.d.ts +1 -0
- package/{build → lib/esm}/dom/fc.test.js +21 -21
- package/lib/esm/dom/form/form.app.d.ts +1 -0
- package/{build → lib/esm}/dom/form/form.app.js +23 -23
- package/lib/esm/dom/form/form.d.ts +26 -0
- package/{build → lib/esm}/dom/form/form.js +34 -34
- package/lib/esm/dom/form/form.test.d.ts +0 -0
- package/lib/esm/dom/form/form.test.js +1 -0
- package/lib/esm/dom/html.d.ts +113 -0
- package/{build → lib/esm}/dom/html.js +114 -114
- package/lib/esm/dom/html.test.d.ts +1 -0
- package/{build → lib/esm}/dom/html.test.js +58 -58
- package/lib/esm/dom/observable.d.ts +2 -0
- package/lib/esm/dom/observable.js +6 -0
- package/lib/esm/dom/observable.test.d.ts +1 -0
- package/lib/esm/dom/observable.test.js +33 -0
- package/lib/esm/dom/provide.d.ts +3 -0
- package/{build → lib/esm}/dom/provide.js +7 -7
- package/lib/esm/dom/router/link.d.ts +6 -0
- package/{build → lib/esm}/dom/router/link.js +3 -3
- package/lib/esm/dom/router/router.d.ts +12 -0
- package/{build → lib/esm}/dom/router/router.js +49 -49
- package/lib/esm/dom/svg.d.ts +64 -0
- package/{build → lib/esm}/dom/svg.js +65 -65
- package/lib/esm/dom/test.d.ts +1 -0
- package/lib/esm/dom/test.js +9 -0
- package/lib/esm/dom/types/css.d.ts +6612 -0
- package/{build → lib/esm}/dom/types/css.js +23 -23
- package/lib/esm/dom/types/dom.d.ts +0 -0
- package/lib/esm/dom/types/dom.js +1 -0
- package/lib/esm/dom/types/html.d.ts +616 -0
- package/{build → lib/esm}/dom/types/html.js +1 -1
- package/lib/esm/dom/xml.d.ts +1 -0
- package/{build → lib/esm}/dom/xml.js +4 -4
- package/lib/esm/equal.d.ts +5 -0
- package/{build → lib/esm}/equal.js +37 -37
- package/lib/esm/equal.test.d.ts +1 -0
- package/{build → lib/esm}/equal.test.js +20 -20
- package/lib/esm/flags.d.ts +7 -0
- package/{build → lib/esm}/flags.js +48 -48
- package/lib/esm/flags.test.d.ts +1 -0
- package/{build → lib/esm}/flags.test.js +35 -35
- package/lib/esm/fs.d.ts +48 -0
- package/{build → lib/esm}/fs.js +144 -144
- package/lib/esm/fs.test.d.ts +1 -0
- package/{build → lib/esm}/fs.test.js +43 -43
- package/lib/esm/generator.d.ts +1 -0
- package/{build → lib/esm}/generator.js +10 -10
- package/lib/esm/generator.test.d.ts +1 -0
- package/{build → lib/esm}/generator.test.js +24 -24
- package/lib/esm/is_browser.d.ts +1 -0
- package/{build → lib/esm}/is_browser.js +1 -1
- package/lib/esm/loader.d.mts +22 -0
- package/{build → lib/esm}/loader.mjs +35 -35
- package/lib/esm/lock.d.ts +1 -0
- package/{build → lib/esm}/lock.js +23 -23
- package/lib/esm/lock.test.d.ts +1 -0
- package/{build → lib/esm}/lock.test.js +16 -16
- package/lib/esm/log.d.ts +26 -0
- package/{build → lib/esm}/log.js +46 -46
- package/lib/esm/observable/event.d.ts +35 -0
- package/lib/esm/observable/event.js +46 -0
- package/lib/esm/observable/observable.d.ts +132 -0
- package/lib/esm/observable/observable.js +343 -0
- package/lib/esm/observable/observable.test.d.ts +1 -0
- package/lib/esm/observable/observable.test.js +63 -0
- package/lib/esm/range.d.ts +1 -0
- package/{build → lib/esm}/range.js +7 -7
- package/lib/esm/result.d.ts +31 -0
- package/{build → lib/esm}/result.js +65 -65
- package/lib/esm/result.test.d.ts +1 -0
- package/{build → lib/esm}/result.test.js +71 -71
- package/lib/esm/safe.d.ts +1 -0
- package/{build → lib/esm}/safe.js +10 -10
- package/lib/esm/scope/describe.d.ts +18 -0
- package/{build → lib/esm}/scope/describe.js +60 -61
- package/lib/esm/scope/display/console.d.ts +2 -0
- package/{build → lib/esm}/scope/display/console.js +21 -21
- package/lib/esm/scope/display/dom.d.ts +3 -0
- package/{build → lib/esm}/scope/display/dom.js +26 -26
- package/lib/esm/scope/display/junit.d.ts +2 -0
- package/{build → lib/esm}/scope/display/junit.js +17 -17
- package/lib/esm/scope/execute.d.ts +12 -0
- package/{build → lib/esm}/scope/execute.js +85 -85
- package/lib/esm/scope/expect.d.ts +23 -0
- package/{build → lib/esm}/scope/expect.js +108 -108
- package/lib/esm/scope/fix.d.ts +4 -0
- package/{build → lib/esm}/scope/fix.js +22 -22
- package/lib/esm/scope/index.d.ts +3 -0
- package/{build → lib/esm}/scope/index.js +3 -3
- package/lib/esm/scope/scope.d.ts +17 -0
- package/{build → lib/esm}/scope/scope.js +1 -1
- package/lib/esm/scope/state.d.ts +1 -0
- package/lib/esm/scope/state.js +7 -0
- package/lib/esm/server/http/apps.d.ts +5 -0
- package/{build → lib/esm}/server/http/apps.js +23 -23
- package/lib/esm/server/http/css.d.ts +5 -0
- package/{build → lib/esm}/server/http/css.js +50 -50
- package/lib/esm/server/http/index.d.ts +21 -0
- package/{build → lib/esm}/server/http/index.js +73 -73
- package/lib/esm/server/http/response.d.ts +4 -0
- package/{build → lib/esm}/server/http/response.js +40 -40
- package/lib/esm/server/http/sitemap.d.ts +2 -0
- package/{build → lib/esm}/server/http/sitemap.js +42 -42
- package/lib/esm/server/http/static.d.ts +2 -0
- package/{build → lib/esm}/server/http/static.js +21 -21
- package/lib/esm/server/http/typescript.d.ts +5 -0
- package/{build → lib/esm}/server/http/typescript.js +40 -40
- package/lib/esm/server/main.d.ts +2 -0
- package/{build → lib/esm}/server/main.js +12 -9
- package/lib/esm/test.d.mts +2 -0
- package/lib/esm/test.mjs +26 -0
- package/lib/esm/test_all.d.ts +9 -0
- package/{build → lib/esm}/test_all.js +28 -18
- package/lib/esm/transpile.d.mts +3 -0
- package/{build → lib/esm}/transpile.mjs +18 -18
- package/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/package.json +13 -14
- package/src/assert.ts +1 -1
- package/src/components/button_bar.ts +3 -3
- package/src/components/inline_edit.ts +3 -3
- package/src/components/logger.ts +3 -3
- package/src/components/select.ts +3 -3
- package/src/components/test.js +3 -2
- package/src/context.ts +3 -3
- package/src/diff.ts +2 -2
- package/src/dom/css/border.ts +3 -3
- package/src/dom/css/core.ts +1 -1
- package/src/dom/css/fstyle.ts +2 -2
- package/src/dom/css/sizing.ts +1 -1
- package/src/dom/dom.ts +1 -1
- package/src/dom/fc.test.ts +3 -3
- package/src/dom/fc.ts +1 -1
- package/src/dom/form/form.app.ts +2 -2
- package/src/dom/form/form.ts +3 -3
- package/src/dom/html.test.ts +3 -3
- package/src/dom/html.ts +1 -1
- package/src/dom/observable.test.ts +6 -6
- package/src/dom/observable.ts +1 -1
- package/src/dom/provide.ts +1 -1
- package/src/dom/router/link.ts +2 -2
- package/src/dom/router/router.ts +2 -2
- package/src/dom/svg.ts +1 -1
- package/src/dom/test.ts +8 -6
- package/src/dom/types/html.ts +1 -1
- package/src/equal.ts +1 -1
- package/src/flags.ts +1 -1
- package/src/fs.ts +4 -4
- package/src/index.html +6 -6
- package/src/observable/event.ts +2 -2
- package/src/observable/observable.test.ts +2 -2
- package/src/observable/observable.ts +72 -12
- package/src/pico/_variables.scss +1 -1
- package/src/pico/layout/_sectioning.scss +2 -0
- package/src/result.ts +1 -1
- package/src/scope/describe.ts +2 -5
- package/src/scope/display/console.ts +4 -4
- package/src/scope/display/dom.ts +6 -6
- package/src/scope/display/junit.ts +3 -3
- package/src/scope/execute.ts +2 -2
- package/src/scope/expect.ts +3 -3
- package/src/scope/state.ts +10 -0
- package/src/server/http/sitemap.ts +1 -1
- package/src/server/main.ts +9 -2
- package/src/test.mjs +22 -18
- package/src/test_all.ts +10 -0
- package/build/components/select.d.ts +0 -13
- package/build/components/test.js +0 -2
- package/build/dom/test.d.ts +0 -1
- package/build/dom/test.js +0 -2
- package/build/observable/observable.d.ts +0 -83
- package/build/observable/observable.js +0 -148
- package/build/observable/observable.test.js +0 -21
- package/build/test.mjs +0 -23
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
export function compareArrays(equal) {
|
|
2
|
-
return (a, b, partial = false) => a.length === b.length && a.every((e, i) => equal(e, b[i], partial));
|
|
3
|
-
}
|
|
4
|
-
export const equalArrays = compareArrays(Object.is);
|
|
5
|
-
export const matchArrays = compareArrays(equals);
|
|
6
|
-
function asArray(a) {
|
|
7
|
-
return Object.entries(a).sort((a, b) => a[0].localeCompare(b[0]));
|
|
8
|
-
}
|
|
9
|
-
export const matchObjects = (a, b, partial = true) => {
|
|
10
|
-
for (const [k, v] of Object.entries(a)) {
|
|
11
|
-
if (!b.hasOwnProperty(k) && partial)
|
|
12
|
-
continue;
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
if (!equals(v, b[k], partial))
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
18
|
-
};
|
|
19
|
-
export function equals(a, b, partial = false) {
|
|
20
|
-
// runtime type checking
|
|
21
|
-
switch (typeof a) {
|
|
22
|
-
case "object":
|
|
23
|
-
if (b === undefined) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
if (a instanceof Array && b instanceof Array) {
|
|
27
|
-
return matchArrays(a, b, partial);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return matchObjects(a, b, partial);
|
|
31
|
-
}
|
|
32
|
-
case "function":
|
|
33
|
-
return a.name
|
|
34
|
-
default:
|
|
35
|
-
return Object.is(a, b);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
1
|
+
export function compareArrays(equal) {
|
|
2
|
+
return (a, b, partial = false) => a.length === b.length && a.every((e, i) => equal(e, b[i], partial));
|
|
3
|
+
}
|
|
4
|
+
export const equalArrays = compareArrays(Object.is);
|
|
5
|
+
export const matchArrays = compareArrays(equals);
|
|
6
|
+
function asArray(a) {
|
|
7
|
+
return Object.entries(a).sort((a, b) => a[0].localeCompare(b[0]));
|
|
8
|
+
}
|
|
9
|
+
export const matchObjects = (a, b, partial = true) => {
|
|
10
|
+
for (const [k, v] of Object.entries(a)) {
|
|
11
|
+
if (!b.hasOwnProperty(k) && partial)
|
|
12
|
+
continue;
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
if (!equals(v, b[k], partial))
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
export function equals(a, b, partial = false) {
|
|
20
|
+
// runtime type checking
|
|
21
|
+
switch (typeof a) {
|
|
22
|
+
case "object":
|
|
23
|
+
if (b === undefined) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (a instanceof Array && b instanceof Array) {
|
|
27
|
+
return matchArrays(a, b, partial);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return matchObjects(a, b, partial);
|
|
31
|
+
}
|
|
32
|
+
case "function":
|
|
33
|
+
return a.name === b.name;
|
|
34
|
+
default:
|
|
35
|
+
return Object.is(a, b);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { describe, it, expect } from "./scope/index.js";
|
|
2
|
-
import { equalArrays, equals, matchArrays } from "./equal.js";
|
|
3
|
-
describe("Equality", () => {
|
|
4
|
-
it("compares objects", () => {
|
|
5
|
-
expect(equals({ a: 1, b: 2 }, { b: 2, a: 1 })).toBe(true);
|
|
6
|
-
expect(equals({ a: 1, b: 2 }, { b: 1, a: 2 })).toBe(false);
|
|
7
|
-
});
|
|
8
|
-
it("compares primitives", () => {
|
|
9
|
-
expect(equals(1, 1)).toBe(true);
|
|
10
|
-
expect(equals(1, -1)).toBe(false);
|
|
11
|
-
expect(equals(0, -0)).toBe(false);
|
|
12
|
-
expect(equals(NaN, NaN)).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
it("compares arrays", () => {
|
|
15
|
-
expect(equalArrays([1, 2, 3], [1, 2, 3])).toBe(true);
|
|
16
|
-
expect(equalArrays([1], [2, 3])).toBe(false);
|
|
17
|
-
expect(equalArrays([{ a: 1 }], [{ a: 1 }])).toBe(false);
|
|
18
|
-
expect(matchArrays([{ a: 1 }], [{ a: 1 }])).toBe(true);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
1
|
+
import { describe, it, expect } from "./scope/index.js";
|
|
2
|
+
import { equalArrays, equals, matchArrays } from "./equal.js";
|
|
3
|
+
describe("Equality", () => {
|
|
4
|
+
it("compares objects", () => {
|
|
5
|
+
expect(equals({ a: 1, b: 2 }, { b: 2, a: 1 })).toBe(true);
|
|
6
|
+
expect(equals({ a: 1, b: 2 }, { b: 1, a: 2 })).toBe(false);
|
|
7
|
+
});
|
|
8
|
+
it("compares primitives", () => {
|
|
9
|
+
expect(equals(1, 1)).toBe(true);
|
|
10
|
+
expect(equals(1, -1)).toBe(false);
|
|
11
|
+
expect(equals(0, -0)).toBe(false);
|
|
12
|
+
expect(equals(NaN, NaN)).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
it("compares arrays", () => {
|
|
15
|
+
expect(equalArrays([1, 2, 3], [1, 2, 3])).toBe(true);
|
|
16
|
+
expect(equalArrays([1], [2, 3])).toBe(false);
|
|
17
|
+
expect(equalArrays([{ a: 1 }], [{ a: 1 }])).toBe(false);
|
|
18
|
+
expect(matchArrays([{ a: 1 }], [{ a: 1 }])).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
export const parse = (parseArgs) => {
|
|
2
|
-
const fromNode = parseArgs[0].endsWith("node");
|
|
3
|
-
const argv = parseArgs[fromNode ? 1 : 0];
|
|
4
|
-
const params = new Map();
|
|
5
|
-
const flags = new Map();
|
|
6
|
-
const args = [];
|
|
7
|
-
let index = fromNode ? 2 : 1;
|
|
8
|
-
const hasNext = () => index < parseArgs.length;
|
|
9
|
-
const peek = () => parseArgs[index];
|
|
10
|
-
const advance = () => parseArgs[index++];
|
|
11
|
-
const parseLong = (arg) => {
|
|
12
|
-
if (arg.substr(0, 3) === "no-") {
|
|
13
|
-
flags.set(arg.substr(3), false);
|
|
14
|
-
}
|
|
15
|
-
else if (!arg.includes("=")) {
|
|
16
|
-
flags.set(arg, true);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
const [param, ...value] = arg.split("=");
|
|
20
|
-
params.set(param, value.join("="));
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
while (hasNext()) {
|
|
24
|
-
if (peek().substr(0, 2)
|
|
25
|
-
parseLong(advance().substr(2));
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
args.push(advance());
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
get argv0() {
|
|
33
|
-
return argv;
|
|
34
|
-
},
|
|
35
|
-
get args() {
|
|
36
|
-
return args;
|
|
37
|
-
},
|
|
38
|
-
get(flag, def = false) {
|
|
39
|
-
return flags.get(flag) ?? def;
|
|
40
|
-
},
|
|
41
|
-
asNumber(param, def = 0) {
|
|
42
|
-
return Number.parseFloat(params.get(param) ?? `${def}`);
|
|
43
|
-
},
|
|
44
|
-
asString(param, def = "") {
|
|
45
|
-
return params.get(param) ?? def;
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
};
|
|
1
|
+
export const parse = (parseArgs) => {
|
|
2
|
+
const fromNode = parseArgs[0].endsWith("node");
|
|
3
|
+
const argv = parseArgs[fromNode ? 1 : 0];
|
|
4
|
+
const params = new Map();
|
|
5
|
+
const flags = new Map();
|
|
6
|
+
const args = [];
|
|
7
|
+
let index = fromNode ? 2 : 1;
|
|
8
|
+
const hasNext = () => index < parseArgs.length;
|
|
9
|
+
const peek = () => parseArgs[index];
|
|
10
|
+
const advance = () => parseArgs[index++];
|
|
11
|
+
const parseLong = (arg) => {
|
|
12
|
+
if (arg.substr(0, 3) === "no-") {
|
|
13
|
+
flags.set(arg.substr(3), false);
|
|
14
|
+
}
|
|
15
|
+
else if (!arg.includes("=")) {
|
|
16
|
+
flags.set(arg, true);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const [param, ...value] = arg.split("=");
|
|
20
|
+
params.set(param, value.join("="));
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
while (hasNext()) {
|
|
24
|
+
if (peek().substr(0, 2) === "--") {
|
|
25
|
+
parseLong(advance().substr(2));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
args.push(advance());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
get argv0() {
|
|
33
|
+
return argv;
|
|
34
|
+
},
|
|
35
|
+
get args() {
|
|
36
|
+
return args;
|
|
37
|
+
},
|
|
38
|
+
get(flag, def = false) {
|
|
39
|
+
return flags.get(flag) ?? def;
|
|
40
|
+
},
|
|
41
|
+
asNumber(param, def = 0) {
|
|
42
|
+
return Number.parseFloat(params.get(param) ?? `${def}`);
|
|
43
|
+
},
|
|
44
|
+
asString(param, def = "") {
|
|
45
|
+
return params.get(param) ?? def;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { describe, it, expect } from "./scope/index.js";
|
|
2
|
-
import { parse } from "./flags.js";
|
|
3
|
-
const TEST_CASES = {
|
|
4
|
-
SIMPLE: "program",
|
|
5
|
-
NODE: "/usr/local/bin/node program",
|
|
6
|
-
ONE_FLAG: "program --fun",
|
|
7
|
-
ONE_PARAM: "program --fun=100",
|
|
8
|
-
ONE_ARG: "program cat",
|
|
9
|
-
ONE_NO_FLAG: "program --no-fun",
|
|
10
|
-
MIXED: "program --fun=dog cat --port=8080 mouse --hamster --no-bird",
|
|
11
|
-
};
|
|
12
|
-
const makeFlags = (commandLine) => {
|
|
13
|
-
return parse(commandLine.split(" "));
|
|
14
|
-
};
|
|
15
|
-
describe("Flags", () => {
|
|
16
|
-
it("stores the program name", () => {
|
|
17
|
-
const flags = makeFlags(TEST_CASES.SIMPLE);
|
|
18
|
-
expect(flags.argv0).toEqual("program");
|
|
19
|
-
expect(flags.args).toEqual([]);
|
|
20
|
-
});
|
|
21
|
-
it("stores the program name ignoring node", () => {
|
|
22
|
-
const flags = makeFlags(TEST_CASES.NODE);
|
|
23
|
-
expect(flags.argv0).toEqual("program");
|
|
24
|
-
expect(flags.args).toEqual([]);
|
|
25
|
-
});
|
|
26
|
-
it("parses a flag", () => {
|
|
27
|
-
const flags = makeFlags(TEST_CASES.ONE_FLAG);
|
|
28
|
-
expect(flags.get("fun")).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
it("parses a flag with a default value", () => {
|
|
31
|
-
const flags = makeFlags(TEST_CASES.SIMPLE);
|
|
32
|
-
expect(flags.get("missing")).toBe(false);
|
|
33
|
-
expect(flags.get("missing", true)).toBe(true);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
1
|
+
import { describe, it, expect } from "./scope/index.js";
|
|
2
|
+
import { parse } from "./flags.js";
|
|
3
|
+
const TEST_CASES = {
|
|
4
|
+
SIMPLE: "program",
|
|
5
|
+
NODE: "/usr/local/bin/node program",
|
|
6
|
+
ONE_FLAG: "program --fun",
|
|
7
|
+
ONE_PARAM: "program --fun=100",
|
|
8
|
+
ONE_ARG: "program cat",
|
|
9
|
+
ONE_NO_FLAG: "program --no-fun",
|
|
10
|
+
MIXED: "program --fun=dog cat --port=8080 mouse --hamster --no-bird",
|
|
11
|
+
};
|
|
12
|
+
const makeFlags = (commandLine) => {
|
|
13
|
+
return parse(commandLine.split(" "));
|
|
14
|
+
};
|
|
15
|
+
describe("Flags", () => {
|
|
16
|
+
it("stores the program name", () => {
|
|
17
|
+
const flags = makeFlags(TEST_CASES.SIMPLE);
|
|
18
|
+
expect(flags.argv0).toEqual("program");
|
|
19
|
+
expect(flags.args).toEqual([]);
|
|
20
|
+
});
|
|
21
|
+
it("stores the program name ignoring node", () => {
|
|
22
|
+
const flags = makeFlags(TEST_CASES.NODE);
|
|
23
|
+
expect(flags.argv0).toEqual("program");
|
|
24
|
+
expect(flags.args).toEqual([]);
|
|
25
|
+
});
|
|
26
|
+
it("parses a flag", () => {
|
|
27
|
+
const flags = makeFlags(TEST_CASES.ONE_FLAG);
|
|
28
|
+
expect(flags.get("fun")).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
it("parses a flag with a default value", () => {
|
|
31
|
+
const flags = makeFlags(TEST_CASES.SIMPLE);
|
|
32
|
+
expect(flags.get("missing")).toBe(false);
|
|
33
|
+
expect(flags.get("missing", true)).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
});
|
package/lib/esm/fs.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare type PathLike = string;
|
|
2
|
+
export interface Stats {
|
|
3
|
+
isDirectory(): boolean;
|
|
4
|
+
isFile(): boolean;
|
|
5
|
+
}
|
|
6
|
+
interface FileSystemAdapter {
|
|
7
|
+
stat(path: PathLike): Promise<Stats>;
|
|
8
|
+
readdir(path: PathLike): Promise<string[]>;
|
|
9
|
+
copyFile(from: PathLike, to: PathLike): Promise<void>;
|
|
10
|
+
readFile(path: PathLike): Promise<string>;
|
|
11
|
+
writeFile(path: PathLike, contents: string): Promise<void>;
|
|
12
|
+
rm(path: PathLike): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare class FileSystem implements FileSystemAdapter {
|
|
15
|
+
protected adapter: ObjectFileSystemAdapter;
|
|
16
|
+
protected wd: string;
|
|
17
|
+
protected stack: string[];
|
|
18
|
+
constructor(adapter?: ObjectFileSystemAdapter);
|
|
19
|
+
cwd(): string;
|
|
20
|
+
cd(dir: string): void;
|
|
21
|
+
pushd(dir: string): void;
|
|
22
|
+
popd(): void;
|
|
23
|
+
stat(path: PathLike): Promise<Stats>;
|
|
24
|
+
readdir(path: PathLike): Promise<string[]>;
|
|
25
|
+
copyFile(from: PathLike, to: PathLike): Promise<void>;
|
|
26
|
+
readFile(path: PathLike): Promise<string>;
|
|
27
|
+
writeFile(path: PathLike, contents: string): Promise<void>;
|
|
28
|
+
rm(path: PathLike): Promise<void>;
|
|
29
|
+
private p;
|
|
30
|
+
}
|
|
31
|
+
export declare class ObjectFileSystemAdapter implements FileSystemAdapter {
|
|
32
|
+
private fs;
|
|
33
|
+
constructor(fs?: Record<string, string>);
|
|
34
|
+
stat(path: PathLike): Promise<Stats>;
|
|
35
|
+
readdir(path: PathLike): Promise<string[]>;
|
|
36
|
+
copyFile(from: PathLike, to: PathLike): Promise<void>;
|
|
37
|
+
readFile(path: PathLike): Promise<string>;
|
|
38
|
+
writeFile(path: PathLike, contents: string): Promise<void>;
|
|
39
|
+
rm(path: PathLike): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export declare class LocalStorageFileSystemAdapter extends ObjectFileSystemAdapter {
|
|
42
|
+
constructor();
|
|
43
|
+
}
|
|
44
|
+
export interface Tree {
|
|
45
|
+
[k: string]: string | Tree;
|
|
46
|
+
}
|
|
47
|
+
export declare function reset(fs: FileSystem, tree: Tree): Promise<void>;
|
|
48
|
+
export {};
|
package/{build → lib/esm}/fs.js
RENAMED
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
function join(...paths) {
|
|
2
|
-
const pathParts = [];
|
|
3
|
-
for (const path of paths) {
|
|
4
|
-
for (const part of path.split("/")) {
|
|
5
|
-
switch (part) {
|
|
6
|
-
case "":
|
|
7
|
-
case ".":
|
|
8
|
-
break;
|
|
9
|
-
case "..":
|
|
10
|
-
pathParts.pop();
|
|
11
|
-
break;
|
|
12
|
-
default:
|
|
13
|
-
pathParts.push(part);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return "/" + pathParts.join("/");
|
|
18
|
-
}
|
|
19
|
-
export class FileSystem {
|
|
20
|
-
adapter;
|
|
21
|
-
wd = "/";
|
|
22
|
-
stack = [];
|
|
23
|
-
constructor(adapter = new ObjectFileSystemAdapter()) {
|
|
24
|
-
this.adapter = adapter;
|
|
25
|
-
}
|
|
26
|
-
cwd() {
|
|
27
|
-
return this.wd;
|
|
28
|
-
}
|
|
29
|
-
cd(dir) {
|
|
30
|
-
this.wd = this.p(dir);
|
|
31
|
-
}
|
|
32
|
-
pushd(dir) {
|
|
33
|
-
this.stack.push(this.wd);
|
|
34
|
-
this.cd(dir);
|
|
35
|
-
}
|
|
36
|
-
popd() {
|
|
37
|
-
if (this.stack.length > 0) {
|
|
38
|
-
this.wd = this.stack.pop();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
stat(path) {
|
|
42
|
-
return this.adapter.stat(join(this.cwd(), path));
|
|
43
|
-
}
|
|
44
|
-
readdir(path) {
|
|
45
|
-
return this.adapter.readdir(this.p(path) + "/");
|
|
46
|
-
}
|
|
47
|
-
copyFile(from, to) {
|
|
48
|
-
return this.adapter.copyFile(this.p(from), this.p(to));
|
|
49
|
-
}
|
|
50
|
-
readFile(path) {
|
|
51
|
-
return this.adapter.readFile(this.p(path));
|
|
52
|
-
}
|
|
53
|
-
writeFile(path, contents) {
|
|
54
|
-
return this.adapter.writeFile(this.p(path), contents);
|
|
55
|
-
}
|
|
56
|
-
rm(path) {
|
|
57
|
-
return this.adapter.rm(this.p(path));
|
|
58
|
-
}
|
|
59
|
-
p(path) {
|
|
60
|
-
return path[0]
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export class ObjectFileSystemAdapter {
|
|
64
|
-
fs;
|
|
65
|
-
constructor(fs = {}) {
|
|
66
|
-
this.fs = fs;
|
|
67
|
-
}
|
|
68
|
-
stat(path) {
|
|
69
|
-
return new Promise((resolve, reject) => {
|
|
70
|
-
if (this.fs[path] != null) {
|
|
71
|
-
resolve({
|
|
72
|
-
isDirectory() {
|
|
73
|
-
return false;
|
|
74
|
-
},
|
|
75
|
-
isFile() {
|
|
76
|
-
return true;
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
reject();
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
readdir(path) {
|
|
86
|
-
return new Promise((resolve) => {
|
|
87
|
-
let dir = [];
|
|
88
|
-
for (const filename of Object.keys(this.fs)) {
|
|
89
|
-
if (filename.startsWith(path)) {
|
|
90
|
-
const end = filename.indexOf("/", path.length + 1);
|
|
91
|
-
const basename = filename.substring(path.length, end
|
|
92
|
-
dir.push(basename);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return resolve(dir);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
copyFile(from, to) {
|
|
99
|
-
return new Promise((resolve) => {
|
|
100
|
-
this.fs[to] = this.fs[from];
|
|
101
|
-
resolve();
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
readFile(path) {
|
|
105
|
-
return new Promise((resolve, reject) => {
|
|
106
|
-
let file = this.fs[path];
|
|
107
|
-
if (file === undefined) {
|
|
108
|
-
reject();
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
resolve(file);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
writeFile(path, contents) {
|
|
116
|
-
return new Promise((resolve) => {
|
|
117
|
-
this.fs[path] = contents;
|
|
118
|
-
resolve();
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
rm(path) {
|
|
122
|
-
return new Promise((resolve) => {
|
|
123
|
-
delete this.fs[path];
|
|
124
|
-
resolve();
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
export class LocalStorageFileSystemAdapter extends ObjectFileSystemAdapter {
|
|
129
|
-
constructor() {
|
|
130
|
-
super(window.localStorage);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
export async function reset(fs, tree) {
|
|
134
|
-
for (const [path, file] of Object.entries(tree)) {
|
|
135
|
-
if (typeof file
|
|
136
|
-
await fs.writeFile(path, file);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
fs.cd(path);
|
|
140
|
-
await reset(fs, file);
|
|
141
|
-
fs.cd("..");
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
1
|
+
function join(...paths) {
|
|
2
|
+
const pathParts = [];
|
|
3
|
+
for (const path of paths) {
|
|
4
|
+
for (const part of path.split("/")) {
|
|
5
|
+
switch (part) {
|
|
6
|
+
case "":
|
|
7
|
+
case ".":
|
|
8
|
+
break;
|
|
9
|
+
case "..":
|
|
10
|
+
pathParts.pop();
|
|
11
|
+
break;
|
|
12
|
+
default:
|
|
13
|
+
pathParts.push(part);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return "/" + pathParts.join("/");
|
|
18
|
+
}
|
|
19
|
+
export class FileSystem {
|
|
20
|
+
adapter;
|
|
21
|
+
wd = "/";
|
|
22
|
+
stack = [];
|
|
23
|
+
constructor(adapter = new ObjectFileSystemAdapter()) {
|
|
24
|
+
this.adapter = adapter;
|
|
25
|
+
}
|
|
26
|
+
cwd() {
|
|
27
|
+
return this.wd;
|
|
28
|
+
}
|
|
29
|
+
cd(dir) {
|
|
30
|
+
this.wd = this.p(dir);
|
|
31
|
+
}
|
|
32
|
+
pushd(dir) {
|
|
33
|
+
this.stack.push(this.wd);
|
|
34
|
+
this.cd(dir);
|
|
35
|
+
}
|
|
36
|
+
popd() {
|
|
37
|
+
if (this.stack.length > 0) {
|
|
38
|
+
this.wd = this.stack.pop();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
stat(path) {
|
|
42
|
+
return this.adapter.stat(join(this.cwd(), path));
|
|
43
|
+
}
|
|
44
|
+
readdir(path) {
|
|
45
|
+
return this.adapter.readdir(this.p(path) + "/");
|
|
46
|
+
}
|
|
47
|
+
copyFile(from, to) {
|
|
48
|
+
return this.adapter.copyFile(this.p(from), this.p(to));
|
|
49
|
+
}
|
|
50
|
+
readFile(path) {
|
|
51
|
+
return this.adapter.readFile(this.p(path));
|
|
52
|
+
}
|
|
53
|
+
writeFile(path, contents) {
|
|
54
|
+
return this.adapter.writeFile(this.p(path), contents);
|
|
55
|
+
}
|
|
56
|
+
rm(path) {
|
|
57
|
+
return this.adapter.rm(this.p(path));
|
|
58
|
+
}
|
|
59
|
+
p(path) {
|
|
60
|
+
return path[0] === "/" ? path : join(this.cwd(), path);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export class ObjectFileSystemAdapter {
|
|
64
|
+
fs;
|
|
65
|
+
constructor(fs = {}) {
|
|
66
|
+
this.fs = fs;
|
|
67
|
+
}
|
|
68
|
+
stat(path) {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
if (this.fs[path] != null) {
|
|
71
|
+
resolve({
|
|
72
|
+
isDirectory() {
|
|
73
|
+
return false;
|
|
74
|
+
},
|
|
75
|
+
isFile() {
|
|
76
|
+
return true;
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
reject();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
readdir(path) {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
let dir = [];
|
|
88
|
+
for (const filename of Object.keys(this.fs)) {
|
|
89
|
+
if (filename.startsWith(path)) {
|
|
90
|
+
const end = filename.indexOf("/", path.length + 1);
|
|
91
|
+
const basename = filename.substring(path.length, end === -1 ? undefined : end);
|
|
92
|
+
dir.push(basename);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return resolve(dir);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
copyFile(from, to) {
|
|
99
|
+
return new Promise((resolve) => {
|
|
100
|
+
this.fs[to] = this.fs[from];
|
|
101
|
+
resolve();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
readFile(path) {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
let file = this.fs[path];
|
|
107
|
+
if (file === undefined) {
|
|
108
|
+
reject(new Error(`File Not Found ${path}`));
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
resolve(file);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
writeFile(path, contents) {
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
this.fs[path] = contents;
|
|
118
|
+
resolve();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
rm(path) {
|
|
122
|
+
return new Promise((resolve) => {
|
|
123
|
+
delete this.fs[path];
|
|
124
|
+
resolve();
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export class LocalStorageFileSystemAdapter extends ObjectFileSystemAdapter {
|
|
129
|
+
constructor() {
|
|
130
|
+
super(window.localStorage);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export async function reset(fs, tree) {
|
|
134
|
+
for (const [path, file] of Object.entries(tree)) {
|
|
135
|
+
if (typeof file === "string") {
|
|
136
|
+
await fs.writeFile(path, file);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
fs.cd(path);
|
|
140
|
+
await reset(fs, file);
|
|
141
|
+
fs.cd("..");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|