diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18531b3..d36e1a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,11 +12,9 @@ jobs: node-version: - 14 - 12 - - 10 - - 8 steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index 64f4a00..5bcaa07 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,3 @@ -/// - /** Check if a Buffer/Uint8Array is a [PNG](https://en.wikipedia.org/wiki/Portable_Network_Graphics) image. @@ -9,8 +7,8 @@ Check if a Buffer/Uint8Array is a [PNG](https://en.wikipedia.org/wiki/Portable_N @example ``` // Node.js: -import readChunk = require('read-chunk'); -import isPng = require('is-png'); +import readChunk from 'read-chunk'; +import isPng from 'is-png'; const buffer = readChunk.sync('unicorn.png', 0, 8); @@ -18,15 +16,13 @@ isPng(buffer); //=> true // Browser: -(async () => { - const response = await fetch('unicorn.png'); - const buffer = await response.arrayBuffer(); +import readChunk from 'read-chunk'; + +const response = await fetch('unicorn.png'); +const buffer = await response.arrayBuffer(); - isPng(new Uint8Array(buffer)); - //=> true -})(); +isPng(new Uint8Array(buffer)); +//=> true ``` */ -declare function isPng(buffer: Uint8Array | Buffer): boolean; - -export = isPng; +export default function isPng(buffer: Uint8Array | Buffer): boolean; diff --git a/index.js b/index.js index ecc59a5..e619ac7 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,4 @@ -'use strict'; - -module.exports = buffer => { +export default function isPng(buffer) { if (!buffer || buffer.length < 8) { return false; } @@ -15,4 +13,4 @@ module.exports = buffer => { buffer[6] === 0x1A && buffer[7] === 0x0A ); -}; +} diff --git a/index.test-d.ts b/index.test-d.ts index 9a03ae1..39d5ab7 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,13 +1,11 @@ /// import {expectType} from 'tsd'; -import isPng = require('.'); +import isPng from './index.js'; expectType(isPng(new Uint8Array(0))); expectType(isPng(Buffer.from(''))); -(async () => { - const response = await fetch('unicorn.png'); - const buffer = await response.arrayBuffer(); +const response = await fetch('unicorn.png'); +const buffer = await response.arrayBuffer(); - isPng(new Uint8Array(buffer)); -})(); +isPng(new Uint8Array(buffer)); diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/package.json b/package.json index 58cc983..3ac5f00 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,16 @@ "description": "Check if a Buffer/Uint8Array is a PNG image", "license": "MIT", "repository": "sindresorhus/is-png", + "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" + "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=8" + "node": ">=12" }, "scripts": { "test": "xo && ava && tsd" @@ -37,10 +40,10 @@ "uint8array" ], "devDependencies": { - "@types/node": "^11.13.5", - "ava": "^1.4.1", + "@types/node": "^14.14.41", + "ava": "^3.15.0", "read-chunk": "^3.2.0", - "tsd": "^0.7.2", - "xo": "^0.24.0" + "tsd": "^0.14.0", + "xo": "^0.38.2" } } diff --git a/readme.md b/readme.md index f1c77b9..16fff9d 100644 --- a/readme.md +++ b/readme.md @@ -2,21 +2,20 @@ > Check if a Buffer/Uint8Array is a [PNG](https://en.wikipedia.org/wiki/Portable_Network_Graphics) image - ## Install ``` $ npm install is-png ``` - ## Usage ##### Node.js ```js -const readChunk = require('read-chunk'); // npm install read-chunk -const isPng = require('is-png'); +import readChunk from 'read-chunk'; // npm install read-chunk +import isPng from 'is-png'; + const buffer = readChunk.sync('unicorn.png', 0, 8); isPng(buffer); @@ -26,15 +25,14 @@ isPng(buffer); ##### Browser ```js -(async () => { - const response = await fetch('unicorn.png'); - const buffer = await response.arrayBuffer(); +import isPng from 'is-png'; - isPng(new Uint8Array(buffer)); - //=> true -})(); -``` +const response = await fetch('unicorn.png'); +const buffer = await response.arrayBuffer(); +isPng(new Uint8Array(buffer)); +//=> true +``` ## API @@ -46,12 +44,6 @@ Accepts a Buffer (Node.js) or Uint8Array. Returns a `boolean` of whether `buffer The buffer to check. It only needs the first 8 bytes. - ## Related - [file-type](https://github.com/sindresorhus/file-type) - Detect the file type of a Buffer/Uint8Array/ArrayBuffer - - -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/test.js b/test.js index ac90e59..639e762 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,6 @@ import test from 'ava'; import readChunk from 'read-chunk'; -import isPng from '.'; +import isPng from './index.js'; const check = filename => isPng(readChunk.sync(filename, 0, 8));