From 0fa0604cc713b768a62838da0b2625c9a6625941 Mon Sep 17 00:00:00 2001 From: Cayman Date: Fri, 18 Dec 2020 11:18:53 -0700 Subject: [PATCH] feat: aegir types generation (#7) Minimal updates to add autogenerated typescript types via aegir. Used this doc to help: https://github.com/ipfs/aegir/blob/master/md/ts-jsdoc.md I tested this PR locally, linking this to a test project (including updated `web-encoding` dependency) to make sure the types all line up. See https://github.com/achingbrain/uint8arrays/pull/4#issuecomment-731109567 Resolves #3 --- concat.js | 2 +- package.json | 10 +++++++--- test/from-string.spec.js | 2 +- test/to-string.spec.js | 2 +- tsconfig.json | 10 ++++++++++ 5 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 tsconfig.json diff --git a/concat.js b/concat.js index d131858..3c54fe9 100644 --- a/concat.js +++ b/concat.js @@ -4,7 +4,7 @@ * Returns a new Uint8Array created by concatenating the passed ArrayLikes * * @param {Array>} arrays - * @param {Number} length + * @param {Number} [length] * @returns {Uint8Array} */ function concat (arrays, length) { diff --git a/package.json b/package.json index d201156..714e015 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,10 @@ "author": "Alex Potsides ", "homepage": "https://github.com/achingbrain/uint8arrays", "bugs": "https://github.com/achingbrain/uint8arrays/issues", + "types": "dist/src/index.d.ts", + "typesVersions": { + "*": { "*": ["dist/*", "dist/*/index"] } + }, "files": [ "compare.js", "concat.js", @@ -28,15 +32,15 @@ "release": "aegir release --docs", "release-minor": "aegir release --type minor --docs", "release-major": "aegir release --type major --docs", - "build": "aegir build" + "build": "aegir build && aegir ts" }, "license": "MIT", "dependencies": { "multibase": "^3.0.0", - "web-encoding": "^1.0.2" + "web-encoding": "^1.0.5" }, "devDependencies": { - "aegir": "^25.0.0" + "aegir": "^29.2.0" }, "contributors": [ "achingbrain " diff --git a/test/from-string.spec.js b/test/from-string.spec.js index 9ed0fc5..56ffda9 100644 --- a/test/from-string.spec.js +++ b/test/from-string.spec.js @@ -8,7 +8,7 @@ const { TextEncoder } = require('web-encoding') describe('Uint8Array fromString', () => { it('creates a Uint8Array from a string', () => { const str = 'hello world' - const arr = new TextEncoder('utf8').encode(str) + const arr = new TextEncoder().encode(str) expect(fromString(str)).to.deep.equal(arr) }) diff --git a/test/to-string.spec.js b/test/to-string.spec.js index 0761eae..3b21cab 100644 --- a/test/to-string.spec.js +++ b/test/to-string.spec.js @@ -8,7 +8,7 @@ const { TextEncoder } = require('web-encoding') describe('Uint8Array toString', () => { it('creates a String from a Uint8Array', () => { const str = 'hello world' - const arr = new TextEncoder('utf8').encode(str) + const arr = new TextEncoder().encode(str) expect(toString(arr)).to.deep.equal(str) }) diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..5f5c1c3 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "./node_modules/aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "test", // remove this line if you don't want to type-check tests + "." + ] +}