This commit is contained in:
Toastie (DCS Team) 2024-10-06 14:14:08 +13:00
parent b178975581
commit 9a95a840df
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
8 changed files with 1682 additions and 36 deletions

122
.eslintrc.cjs Normal file
View file

@ -0,0 +1,122 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
plugins: [
'@typescript-eslint',
'import'
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript'
],
rules: {
'indent': ['warn', 'tab', {
'SwitchCase': 1,
'MemberExpression': 1,
'flatTernaryExpressions': true,
'ArrayExpression': 'first',
'ObjectExpression': 'first',
}],
'eol-last': ['error', 'always'],
'semi': ['error', 'always'],
'semi-spacing': ['error', { 'before': false, 'after': true }],
'quotes': ['warn', 'single'],
'comma-dangle': ['warn', 'always-multiline'],
'comma-spacing': ['error', { 'before': false, 'after': true }],
'array-bracket-spacing': ['error', 'never'],
'keyword-spacing': ['error', {
'before': true,
'after': true,
}],
'key-spacing': ['error', {
'beforeColon': false,
'afterColon': true,
}],
'arrow-spacing': ['error', {
'before': true,
'after': true,
}],
'brace-style': ['error', '1tbs', {
'allowSingleLine': true,
}],
'padded-blocks': ['error', 'never'],
/* TODO: If you do not use the path alias, you will be warned.
'no-restricted-imports': ['warn', {
'patterns': [
]
}],
*/
'eqeqeq': ['error', 'always', { 'null': 'ignore' }],
'no-multi-spaces': ['error'],
'no-var': ['error'],
'prefer-arrow-callback': ['error'],
'no-throw-literal': ['error'],
'no-param-reassign': ['warn'],
'no-constant-condition': ['warn'],
'no-empty-pattern': ['warn'],
'no-async-promise-executor': ['off'],
'no-useless-escape': ['off'],
'no-multiple-empty-lines': ['error', { 'max': 1 }],
'no-control-regex': ['warn'],
'no-empty': ['warn'],
'no-inner-declarations': ['off'],
'no-sparse-arrays': ['off'],
'nonblock-statement-body-position': ['error', 'beside'],
'object-curly-spacing': ['error', 'always'],
'space-infix-ops': ['error'],
'space-before-blocks': ['error', 'always'],
'padding-line-between-statements': [
'error',
{ 'blankLine': 'always', 'prev': 'function', 'next': '*' },
{ 'blankLine': 'always', 'prev': '*', 'next': 'function' },
],
"lines-between-class-members": "off",
/* It seems that typescript-eslint does not support enforce.
'@typescript-eslint/lines-between-class-members': ['error', {
enforce: [{
blankLine: 'always',
prev: 'method',
next: '*',
}]
}],
*/
'@typescript-eslint/func-call-spacing': ['error', 'never'],
'@typescript-eslint/no-explicit-any': ['warn'],
'@typescript-eslint/no-unused-vars': ['warn'],
'@typescript-eslint/no-unnecessary-condition': ['warn'],
'@typescript-eslint/no-var-requires': ['warn'],
'@typescript-eslint/no-inferrable-types': ['warn'],
'@typescript-eslint/no-empty-function': ['off'],
'@typescript-eslint/no-non-null-assertion': ['warn'],
'@typescript-eslint/explicit-function-return-type': ['off'],
'@typescript-eslint/no-misused-promises': ['error', {
'checksVoidReturn': false,
}],
'@typescript-eslint/consistent-type-imports': 'off',
'@typescript-eslint/prefer-nullish-coalescing': [
'warn',
],
'@typescript-eslint/naming-convention': [
'error',
{
"selector": "typeLike",
"format": ["PascalCase"]
},
{
"selector": "typeParameter",
"format": []
}
],
'import/no-unresolved': ['off'],
'import/no-default-export': ['warn'],
'import/order': ['warn', {
'groups': ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type'],
}]
},
};

6
.gitignore vendored
View file

@ -1,3 +1,5 @@
/built
# Logs # Logs
logs logs
*.log *.log
@ -103,4 +105,6 @@ dist
# TernJS port file # TernJS port file
.tern-port .tern-port
test/exports test/exports
built/index.d.ts
built/index.js

View file

@ -1,10 +1,11 @@
{ {
"name": "@valkyriecoms/sharp-read-bmp", "name": "@valkyriecoms/sharp-read-bmp",
"version": "1.0.0", "version": "1.1.0",
"description": "", "description": "",
"main": "built/index.js", "main": "built/index.js",
"types": "built/index.d.ts", "types": "built/index.d.ts",
"scripts": { "scripts": {
"eslint": "eslint --quiet \"src/**/*.ts\"",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --silent=false --verbose false", "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --silent=false --verbose false",
"build": "tsc" "build": "tsc"
}, },
@ -19,19 +20,23 @@
"dependencies": { "dependencies": {
"decode-bmp": "^0.2.1", "decode-bmp": "^0.2.1",
"decode-ico": "^0.4.1", "decode-ico": "^0.4.1",
"sharp": "^0.31.3" "sharp": "^0.32.6"
}, },
"devDependencies": { "devDependencies": {
"@jest/globals": "^29.4.3", "@jest/globals": "^29.7.0",
"@swc/core": "^1.3.37", "@swc/core": "^1.3.101",
"@swc/jest": "^0.2.24", "@swc/jest": "^0.2.29",
"@types/node": "^18.14.5", "@types/node": "^18.19.4",
"@types/sharp": "^0.31.1", "@types/sharp": "^0.31.1",
"file-type": "^18.2.1", "@typescript-eslint/eslint-plugin": "^6.16.0",
"jest": "^29.4.3", "@typescript-eslint/parser": "^6.16.0",
"mkdirp": "^2.1.4", "eslint": "^8.56.0",
"rimraf": "^4.2.0", "eslint-plugin-import": "^2.29.1",
"typescript": "^4.9.5" "file-type": "^18.7.0",
"jest": "^29.7.0",
"mkdirp": "^2.1.6",
"rimraf": "^4.4.1",
"typescript": "^5.3.3"
}, },
"packageManager": "pnpm@8.15.6+sha512.77b89e9be77a2b06ad8f403a19cae5e22976f61023f98ad323d5c30194958ebc02ee0a6ae5d13ee454f6134e4e8caf29a05f0b1a0e1d2b17bca6b6a1f1159f86" "packageManager": "pnpm@8.15.6+sha512.77b89e9be77a2b06ad8f403a19cae5e22976f61023f98ad323d5c30194958ebc02ee0a6ae5d13ee454f6134e4e8caf29a05f0b1a0e1d2b17bca6b6a1f1159f86"
} }

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
import { readFile } from 'node:fs/promises';
import sharp from 'sharp'; import sharp from 'sharp';
import decodeIco from 'decode-ico'; import decodeIco from 'decode-ico';
import decodeBmp from 'decode-bmp'; import decodeBmp from 'decode-bmp';
import { readFile } from 'node:fs/promises';
export async function sharpBmp( export async function sharpBmp(
source: Buffer | Int8Array | Uint8Array | Uint8ClampedArray | string, source: Buffer | Int8Array | Uint8Array | Uint8ClampedArray | string,
@ -52,4 +52,4 @@ export async function sharpBmp(
} }
return sharp(source, options); return sharp(source, options);
} }

BIN
test/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

View file

@ -15,6 +15,8 @@ await mkdirp(resolve(_dirname, 'exports'));
const favicon = resolve(_dirname, 'favicon.ico'); const favicon = resolve(_dirname, 'favicon.ico');
const faviconPng = resolve(_dirname, 'exports', 'favicon.png'); const faviconPng = resolve(_dirname, 'exports', 'favicon.png');
const bmp = resolve(_dirname, 'test.bmp');
const bmpPng = resolve(_dirname, 'exports', 'test.bmp.png');
describe('test', () => { describe('test', () => {
test('check file-type works', async () => { test('check file-type works', async () => {
@ -51,4 +53,17 @@ describe('test', () => {
expect(sharpCtx).toBeTruthy(); expect(sharpCtx).toBeTruthy();
expect((await sharpCtx.metadata()).format).toBe('png'); expect((await sharpCtx.metadata()).format).toBe('png');
}); });
test('test.bmp', async () => {
const type = await fileTypeFromFile(bmp);
if (!type) throw new Error('file type not found');
const sharpCtx = await sharpBmp(bmp, type.mime);
const metadata = await sharpCtx.metadata();
expect(metadata.format).toBe('raw');
expect(metadata.width).toBe(640);
expect(metadata.height).toBe(360);
await sharpCtx.png().toFile(bmpPng);
const pngType = await fileTypeFromFile(bmpPng);
expect(pngType?.mime).toBe('image/png');
});
}); });

BIN
test/test.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 KiB