istextorbinary
- Version 9.5.0
- Published
- 104 kB
- 3 dependencies
- Artistic-2.0 license
Install
npm i istextorbinary
yarn add istextorbinary
pnpm add istextorbinary
Overview
Determine if a filename and/or buffer is text or binary. Smarter detection than the other solutions.
Index
Functions
Interfaces
Functions
function getEncoding
getEncoding: ( buffer: Buffer | null, opts?: EncodingOpts) => 'utf8' | 'binary' | null;
Get the encoding of a buffer. Checks the start, middle, and end of the buffer for characters that are unrecognized within UTF8 encoding. History has shown that inspection at all three locations is necessary.
Returns
Will be
null
ifbuffer
was not provided. Otherwise will be either'utf8'
or'binary'
function isBinary
isBinary: (filename?: string | null, buffer?: Buffer | null) => boolean | null;
Determine if the filename and/or buffer is binary. Determined by extension checks first (if filename is available), otherwise if unknown extension or no filename, will perform a slower buffer encoding detection. This order is done, as extension checks are quicker, and also because encoding checks cannot guarantee accuracy for chars between utf8 and utf16. The extension checks are performed using the resources https://github.com/bevry/textextensions and https://github.com/bevry/binaryextensions
Parameter filename
The filename for the file/buffer if available
Parameter buffer
The buffer for the file if available
Returns
Will be
null
if neitherfilename
norbuffer
were provided. Otherwise will be a boolean value with the detection result.
function isText
isText: (filename?: string | null, buffer?: Buffer | null) => boolean | null;
Determine if the filename and/or buffer is text. Determined by extension checks first (if filename is available), otherwise if unknown extension or no filename, will perform a slower buffer encoding detection. This order is done, as extension checks are quicker, and also because encoding checks cannot guarantee accuracy for chars between utf8 and utf16. The extension checks are performed using the resources https://github.com/bevry/textextensions and https://github.com/bevry/binaryextensions
Parameter filename
The filename for the file/buffer if available
Parameter buffer
The buffer for the file if available
Returns
Will be
null
if neitherfilename
norbuffer
were provided. Otherwise will be a boolean value with the detection result.
Interfaces
interface EncodingOpts
interface EncodingOpts {}
property chunkBegin
chunkBegin?: number;
If not provided, will check the start, beginning, and end
property chunkLength
chunkLength?: number;
Defaults to 24
Package Files (1)
Dependencies (3)
Dev Dependencies (17)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/istextorbinary
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/istextorbinary)
- HTML<a href="https://www.jsdocs.io/package/istextorbinary"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3229 ms. - Missing or incorrect documentation? Open an issue for this package.