Skip to content

Commit fc02085

Browse files
authored
refactor!: introduce typescript and tooling (#1)
1 parent 10e99eb commit fc02085

File tree

18 files changed

+167
-54
lines changed

18 files changed

+167
-54
lines changed

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extends: cheminfo-typescript

.github/workflows/nodejs.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Node.js CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
nodejs:
11+
# Documentation: https://github.com/zakodium/workflows#nodejs-ci
12+
uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1
13+
with:
14+
lint-check-types: true

.github/workflows/release.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
# Documentation: https://github.com/zakodium/workflows#release
11+
uses: zakodium/workflows/.github/workflows/release.yml@release-v1
12+
with:
13+
npm: true
14+
secrets:
15+
github-token: ${{ secrets.BOT_TOKEN }}
16+
npm-token: ${{ secrets.NPM_BOT_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ jspm_packages
3535

3636
# Optional REPL history
3737
.node_repl_history
38+
39+
lib*

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# jpeg-js
1+
# fast-jpeg
22

33
[![NPM version][npm-image]][npm-url]
44
[![npm download][download-image]][download-url]

package.json

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@
22
"name": "fast-jpeg",
33
"version": "1.0.1",
44
"description": "JPEG image decoder written entirely in JavaScript",
5-
"main": "src/index.js",
5+
"main": "lib/index.js",
6+
"module": "lib-esm/index.js",
7+
"types": "lib/index.d.ts",
68
"files": [
7-
"src"
9+
"src",
10+
"lib-esm",
11+
"lib"
812
],
913
"scripts": {
10-
"test": "echo \"Error: no test specified\" && exit 1"
14+
"check-types": "tsc --noEmit",
15+
"clean": "rimraf lib lib-esm",
16+
"eslint": "eslint src",
17+
"eslint-fix": "npm run eslint -- --fix",
18+
"prepack": "npm run tsc",
19+
"prettier": "prettier --check src",
20+
"prettier-write": "prettier --write src",
21+
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
22+
"test-only": "jest --coverage",
23+
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
24+
"tsc-cjs": "tsc --project tsconfig.cjs.json",
25+
"tsc-esm": "tsc --project tsconfig.esm.json"
1126
},
1227
"repository": {
1328
"type": "git",
@@ -17,11 +32,32 @@
1732
"author": "Michaël Zasso",
1833
"license": "MIT",
1934
"bugs": {
20-
"url": "https://github.com/image-js/jpeg-js/issues"
35+
"url": "https://github.com/image-js/fast-jpeg/issues"
2136
},
22-
"homepage": "https://github.com/image-js/jpeg-js#readme",
37+
"homepage": "https://github.com/image-js/fast-jpeg#readme",
2338
"dependencies": {
24-
"iobuffer": "^2.1.0",
25-
"tiff": "^2.0.0"
39+
"iobuffer": "^5.3.2",
40+
"tiff": "^5.0.3"
41+
},
42+
"devDependencies": {
43+
"@types/jest": "^29.5.1",
44+
"eslint": "^8.41.0",
45+
"eslint-config-cheminfo-typescript": "^11.3.1",
46+
"jest": "^29.5.0",
47+
"prettier": "^2.8.8",
48+
"rimraf": "^5.0.1",
49+
"ts-jest": "^29.1.0",
50+
"typescript": "^5.0.4"
51+
},
52+
"prettier": {
53+
"arrowParens": "always",
54+
"semi": true,
55+
"singleQuote": true,
56+
"tabWidth": 2,
57+
"trailingComma": "all"
58+
},
59+
"jest": {
60+
"preset": "ts-jest",
61+
"testEnvironment": "node"
2662
}
2763
}

src/.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__tests__
2+
.npmignore

src/__tests__/decode.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { readFileSync } from 'node:fs';
2+
import { join } from 'node:path';
3+
4+
import { decode } from '../decode';
5+
6+
function readImage(file: string): Buffer {
7+
return readFileSync(join(__dirname, './img', file));
8+
}
9+
10+
test('should extract exif', () => {
11+
const result = decode(readImage('sample.jpg'));
12+
expect(result.exif).toBeDefined();
13+
14+
const { exif } = result;
15+
expect(exif?.[0].fields.size).toBe(12);
16+
expect(exif?.[0].fields.get(271)).toBe('SONY');
17+
expect(exif?.[0].fields.get(272).trimEnd()).toBe('DSC-HX9V');
18+
expect(exif?.[0].fields.get(274)).toBe(1);
19+
});
File renamed without changes.

0 commit comments

Comments
 (0)