ctx-core 5.18.8 → 5.19.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.
@@ -0,0 +1,11 @@
1
+ /// <reference lib="dom" />
2
+ import { Encoding } from 'node:crypto'
3
+ export class TextDecoderStream extends TransformStream<Uint8Array, string> {
4
+ readonly encoding:string
5
+ readonly fatal:boolean
6
+ readonly ignoreBOM:boolean
7
+ constructor(
8
+ encoding?:Encoding,
9
+ params?:ConstructorParameters<typeof TextDecoder>[1]
10
+ )
11
+ }
@@ -0,0 +1,49 @@
1
+ // Copyright 2016 Google Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ // Polyfill for TextEncoderStream and TextDecoderStream
15
+ // Modified by Sukka (https://skk.moe) to increase compatibility and performance with Bun.
16
+ // TODO: Remove when https://github.com/oven-sh/bun/issues/5648 is implemented
17
+ export class TextDecoderStream extends TransformStream {
18
+ constructor(
19
+ encoding = 'utf-8',
20
+ {
21
+ fatal = false,
22
+ ignoreBOM = false,
23
+ } = {},
24
+ ) {
25
+ const decoder = new TextDecoder(encoding, { fatal, ignoreBOM })
26
+ super({
27
+ transform(chunk, controller) {
28
+ const decoded = decoder.decode(chunk)
29
+ if (decoded.length > 0) {
30
+ controller.enqueue(decoded)
31
+ }
32
+ },
33
+ flush(controller) {
34
+ // If {fatal: false} is in options (the default), then the final call to
35
+ // decode() can produce extra output (usually the unicode replacement
36
+ // character 0xFFFD). When fatal is true, this call is just used for its
37
+ // side-effect of throwing a TypeError exception if the input is
38
+ // incomplete.
39
+ const output = decoder.decode()
40
+ if (output.length > 0) {
41
+ controller.enqueue(output)
42
+ }
43
+ }
44
+ })
45
+ this.encoding = encoding
46
+ this.fatal = fatal
47
+ this.ignoreBOM = ignoreBOM
48
+ }
49
+ }
@@ -0,0 +1,24 @@
1
+ /// <reference lib="dom" />
2
+ import { test } from 'uvu'
3
+ import { equal } from 'uvu/assert'
4
+ import { TextDecoderStream } from './index.js'
5
+ test('TestDecoderStream', async ()=>{
6
+ const encoder = new TextEncoder()
7
+ const encoded = encoder.encode('foo\nbar\nbaz')
8
+ let decoded = ''
9
+ const stream = new ReadableStream({
10
+ start(controller) {
11
+ controller.enqueue(encoded)
12
+ controller.close()
13
+ }
14
+ })
15
+ .pipeThrough(new TextDecoderStream())
16
+ .pipeTo(new WritableStream({
17
+ write(chunk) {
18
+ decoded += chunk
19
+ },
20
+ }))
21
+ await stream
22
+ equal(decoded, 'foo\nbar\nbaz')
23
+ })
24
+ test.run()
@@ -0,0 +1,4 @@
1
+ /// <reference lib="dom" />
2
+ export class TextEncoderStream extends TransformStream<string, Uint8Array>{
3
+ constructor()
4
+ }
@@ -0,0 +1,39 @@
1
+ // Copyright 2016 Google Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ // Polyfill for TextEncoderStream and TextDecoderStream
15
+ // TODO: Remove when https://github.com/oven-sh/bun/issues/5648 is implemented
16
+ export class TextEncoderStream extends TransformStream {
17
+ constructor() {
18
+ const decoder = new TextEncoder()
19
+ super({
20
+ transform(chunk, controller) {
21
+ const encoded = decoder.encode(chunk)
22
+ if (encoded.length > 0) {
23
+ controller.enqueue(encoded)
24
+ }
25
+ },
26
+ flush(controller) {
27
+ // If {fatal: false} is in options (the default), then the final call to
28
+ // decode() can produce extra output (usually the unicode replacement
29
+ // character 0xFFFD). When fatal is true, this call is just used for its
30
+ // side-effect of throwing a TypeError exception if the input is
31
+ // incomplete.
32
+ const output = decoder.encode()
33
+ if (output.length > 0) {
34
+ controller.enqueue(output)
35
+ }
36
+ }
37
+ })
38
+ }
39
+ }
@@ -0,0 +1,24 @@
1
+ /// <reference lib="dom" />
2
+ import { test } from 'uvu'
3
+ import { equal } from 'uvu/assert'
4
+ import { TextEncoderStream } from './index.js'
5
+ test('TestEncoderStream', async ()=>{
6
+ const decoded = 'foo\nbar\nbaz'
7
+ let uint8:Uint8Array|undefined = undefined
8
+ const stream = new ReadableStream({
9
+ start(controller) {
10
+ controller.enqueue(decoded)
11
+ controller.close()
12
+ }
13
+ })
14
+ .pipeThrough(new TextEncoderStream())
15
+ .pipeTo(new WritableStream({
16
+ write(chunk) {
17
+ uint8 = chunk
18
+ },
19
+ }))
20
+ await stream
21
+ const decoder = new TextDecoder()
22
+ equal(decoder.decode(uint8), 'foo\nbar\nbaz')
23
+ })
24
+ test.run()
@@ -5,8 +5,9 @@ import { process_release_name } from '../process_release_name/index.js'
5
5
  * @see {@link https://stackoverflow.com/a/70981544/142571}
6
6
  */
7
7
  export const crypto = globalThis.crypto
8
+ let node_crypto = 'node:crypto'
8
9
  export async function crypto_() {
9
10
  return (
10
11
  crypto
11
- || process_release_name && import('node:crypto').then(mod=>mod.webcrypto))
12
+ || process_release_name && import(node_crypto).then(mod=>mod.webcrypto))
12
13
  }
@@ -1,5 +1,6 @@
1
1
  import { process_release_name } from '../process_release_name/index.js'
2
2
  import { waitfor } from '../waitfor/index.js'
3
+ let node_fs_promises = 'node:fs/promises'
3
4
  /**
4
5
  * @param {string}path
5
6
  * @returns {Promise<boolean>}
@@ -8,7 +9,7 @@ import { waitfor } from '../waitfor/index.js'
8
9
  export async function file_exists_(path) {
9
10
  return (
10
11
  (process_release_name ?? false)
11
- && import('node:fs/promises').then(({ access, constants })=>
12
+ && import(node_fs_promises).then(({ access, constants })=>
12
13
  access(path, constants.F_OK)
13
14
  .then(()=>true)
14
15
  .catch(()=>false)))
package/all/index.d.ts CHANGED
@@ -14,6 +14,8 @@ export * from './NumericUnit/index.js'
14
14
  export * from './PHI/index.js'
15
15
  export * from './Request/index.js'
16
16
  export * from './Response/index.js'
17
+ export * from './TextDecoderStream/index.js'
18
+ export * from './TextEncoderStream/index.js'
17
19
  export * from './VERSION/index.js'
18
20
  export * from './a/index.js'
19
21
  export * from './a_assign/index.js'
package/all/index.js CHANGED
@@ -14,6 +14,8 @@ export * from './NumericUnit/index.js'
14
14
  export * from './PHI/index.js'
15
15
  export * from './Request/index.js'
16
16
  export * from './Response/index.js'
17
+ export * from './TextDecoderStream/index.js'
18
+ export * from './TextEncoderStream/index.js'
17
19
  export * from './VERSION/index.js'
18
20
  export * from './a/index.js'
19
21
  export * from './a_assign/index.js'
@@ -1,8 +1,9 @@
1
1
  import { process_release_name } from '../process_release_name/index.js'
2
+ let node_path = 'node:path'
2
3
  export function is_entry_file_(url, entry_path) {
3
4
  if (!process_release_name) return false
4
5
  return (
5
- import('node:path').then(({ resolve })=>
6
+ import(node_path).then(({ resolve })=>
6
7
  new URL(url).pathname === resolve(entry_path ?? process.argv[1]))
7
8
  )
8
9
  }
@@ -1,5 +1,7 @@
1
1
  import { crypto_ } from '../crypto/index.js'
2
2
  import { url__join } from '../url__join/index.js'
3
+ let node_fs_promises = 'node:fs/promises'
4
+ let node_os = 'node:os'
3
5
  /**
4
6
  * @param {string}[dir_path]
5
7
  * @param {string}[extension]
@@ -13,9 +15,9 @@ export async function tempfile_path_(
13
15
  if (dir_path == null) {
14
16
  dir_path =
15
17
  typeof window === 'undefined'
16
- ? await import('node:fs/promises')
18
+ ? await import(node_fs_promises)
17
19
  .then(fs=>
18
- import('node:os')
20
+ import(node_os)
19
21
  .then(os=>
20
22
  fs.realpath(os.tmpdir())))
21
23
  : null
package/html/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { html_ } from '../html/index.js'
1
+ import { html_ } from './/index.js'
2
2
  import { html_attr_, raw__html_attr_ } from '../all/html_attr/index.js'
3
3
  import { html_attrs_ } from '../all/html_attrs/index.js'
4
4
  import { html_class_, html_class__ } from '../all/html_class/index.js'
package/html/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { html_ } from '../html/index.js'
1
+ import { html_ } from './/index.js'
2
2
  import { html_attr_, raw__html_attr_ } from '../all/html_attr/index.js'
3
3
  import { html_attrs_ } from '../all/html_attrs/index.js'
4
4
  import { html_class_, html_class__ } from '../all/html_class/index.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "5.18.8",
3
+ "version": "5.19.0",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -66,6 +66,7 @@
66
66
  "run",
67
67
  "set",
68
68
  "sleep",
69
+ "stream",
69
70
  "string",
70
71
  "tempfile",
71
72
  "test",
@@ -76,7 +77,6 @@
76
77
  "uuid",
77
78
  "package.json"
78
79
  ],
79
- "types": "./src/index.d.ts",
80
80
  "exports": {
81
81
  ".": "./index.js",
82
82
  "./all": "./all/index.js",
@@ -120,6 +120,7 @@
120
120
  "./run": "./run/index.js",
121
121
  "./set": "./set/index.js",
122
122
  "./sleep": "./sleep/index.js",
123
+ "./stream": "./stream/index.js",
123
124
  "./string": "./string/index.js",
124
125
  "./tempfile": "./tempfile/index.js",
125
126
  "./test": "./test/index.js",
@@ -134,7 +135,7 @@
134
135
  "@arethetypeswrong/cli": "^0.13.5",
135
136
  "@ctx-core/preprocess": "^0.1.1",
136
137
  "@size-limit/preset-small-lib": "^11.0.1",
137
- "@types/node": "^20.11.2",
138
+ "@types/node": "^20.11.3",
138
139
  "@types/sinon": "^17.0.3",
139
140
  "c8": "^9.1.0",
140
141
  "check-dts": "^0.7.2",
package/rmemo/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { memo__bind, rmemo__off, rmemo__on, rmemo__add } from '../rmemo/index.js'
1
+ import { memo__bind, rmemo__off, rmemo__on, rmemo__add } from './/index.js'
2
2
  export { memo__bind as _, memo__bind as bind, rmemo__off as off, rmemo__on as on, rmemo__add as subscribe }
3
3
  export * from '../all/be/index.js'
4
4
  export * from '../all/be_/index.js'
package/rmemo/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { memo__bind, rmemo__add, rmemo__off, rmemo__on } from '../rmemo/index.js'
1
+ import { memo__bind, rmemo__add, rmemo__off, rmemo__on } from './/index.js'
2
2
  export { memo__bind as _, memo__bind as bind, rmemo__off as off, rmemo__on as on, rmemo__add as subscribe }
3
3
  export * from '../all/be/index.js'
4
4
  export * from '../all/be_/index.js'
@@ -0,0 +1,2 @@
1
+ export * from '../all/TextDecoderStream/index.js'
2
+ export * from '../all/TextEncoderStream/index.js'
@@ -0,0 +1,2 @@
1
+ export * from '../all/TextDecoderStream/index.js'
2
+ export * from '../all/TextEncoderStream/index.js'
package/tsconfig.json CHANGED
@@ -5,6 +5,7 @@
5
5
  "moduleResolution": "nodenext",
6
6
  "target": "ESNext",
7
7
  "strict": true,
8
+ "esModuleInterop": true,
8
9
  "lib": ["ESNext"],
9
10
  "types": [
10
11
  "node"