File tree Expand file tree Collapse file tree 11 files changed +112
-5
lines changed Expand file tree Collapse file tree 11 files changed +112
-5
lines changed Original file line number Diff line number Diff line change @@ -37,10 +37,29 @@ jobs:
37
37
- name : Type Check
38
38
run : npm run check --if-present
39
39
- name : Test ES
40
- if : ${{matrix.node-version < 12 }}
40
+ if : ${{!startsWith( matrix.node-version, '10.') }}
41
41
run : npm run test:es --if-present
42
42
- name : Test CommonJS
43
43
run : npm run test:cjs --if-present
44
+ validate-types :
45
+ name : Check type use
46
+ runs-on : ubuntu-latest
47
+ strategy :
48
+ matrix :
49
+ test-package : ['ts', 'esm', 'cjs']
50
+ steps :
51
+ - uses : actions/checkout@v2
52
+ - name : Cache node_modules
53
+ id : cache-modules
54
+ uses : actions/cache@v1
55
+ with :
56
+ path : node_modules
57
+ key : 12.x-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
58
+ - name : Install
59
+ if : steps.cache-modules.outputs.cache-hit != 'true'
60
+ run : npm install
61
+ - name : Test ${{ matrix.test-package }}
62
+ run : npm run test:types:${{matrix.test-package}}
44
63
publish :
45
64
name : Publish
46
65
needs : test
Original file line number Diff line number Diff line change 1
1
node_modules
2
+ test /** /package-lock.json
Original file line number Diff line number Diff line change 23
23
"test:browser" : " playwright-test test/test-*.cjs" ,
24
24
"test:es" : " mocha test/test-*.spec.js" ,
25
25
"test:cjs" : " npm run test:node && npm run test:browser" ,
26
- "test" : " npm run test:es && npm run test:cjs"
26
+ "test:types:ts" : " npm test --prefix test/ts-use" ,
27
+ "test:types:esm" : " npm test --prefix test/esm-use" ,
28
+ "test:types:cjs" : " npm test --prefix test/cjs-use" ,
29
+ "test:types" : " npm run test:types:ts && npm run test:types:esm && npm run test:types:cjs" ,
30
+ "test" : " npm run test:es && npm run test:cjs && npm run test:types"
27
31
},
28
32
"license" : " MIT" ,
29
33
"author" :
" Irakli Gozalishvili <[email protected] >" ,
Original file line number Diff line number Diff line change 1
- type Encoder = TextEncoder
2
- type Decoder = TextDecoder
1
+ declare var TextEncoder : typeof self . TextEncoder
2
+ declare var TextDecoder : typeof self . TextDecoder
3
3
4
- export { Encoder as TextEncoder , Decoder as TextDecoder }
4
+ export { TextEncoder , TextDecoder }
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " cjs-use" ,
3
+ "private" : true ,
4
+ "dependencies" : {
5
+ "web-encoding" : " file:../.."
6
+ },
7
+ "scripts" : {
8
+ "test" : " npm install && npx typescript --noEmit --allowJs --checkJs src/main.js"
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ // @ts -check
2
+
3
+ const { TextEncoder, TextDecoder } = require ( "web-encoding" )
4
+
5
+ /**
6
+ * @param {string } text
7
+ * @returns {Uint8Array }
8
+ */
9
+ const encode = ( text ) =>
10
+ new TextEncoder ( ) . encode ( text )
11
+
12
+ /**
13
+ * @param {Uint8Array } bytes
14
+ * @returns {string }
15
+ */
16
+ const decode = ( bytes ) =>
17
+ new TextDecoder ( ) . decode ( bytes )
18
+
19
+ module . exports = { encode, decode }
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " esm-use" ,
3
+ "private" : true ,
4
+ "dependencies" : {
5
+ "web-encoding" : " file:../.."
6
+ },
7
+ "scripts" : {
8
+ "test" : " npm install && npx typescript --noEmit --allowJs --checkJs src/main.js"
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ // @ts -check
2
+
3
+ import { TextEncoder , TextDecoder } from "web-encoding"
4
+
5
+ /**
6
+ * @param {string } text
7
+ * @returns {Uint8Array }
8
+ */
9
+ export const encode = ( text ) =>
10
+ new TextEncoder ( ) . encode ( text )
11
+
12
+ /**
13
+ * @param {Uint8Array } bytes
14
+ * @returns {string }
15
+ */
16
+ export const decode = ( bytes ) =>
17
+ new TextDecoder ( ) . decode ( bytes )
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " ts-use" ,
3
+ "private" : true ,
4
+ "dependencies" : {
5
+ "web-encoding" : " file:../.."
6
+ },
7
+ "scripts" : {
8
+ "test" : " npm install && npx typescript --noEmit"
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ import { TextEncoder , TextDecoder } from "web-encoding"
2
+
3
+ export const encode = ( text :string ) :Uint8Array =>
4
+ new TextEncoder ( ) . encode ( text )
5
+
6
+ export const decode = ( bytes :Uint8Array ) :string =>
7
+ new TextDecoder ( ) . decode ( bytes )
You can’t perform that action at this time.
0 commit comments