fix: update import paths
This commit is contained in:
parent
6e492286b4
commit
cb5f404817
|
@ -1,5 +1,5 @@
|
||||||
import { Context, Recogniser } from '.';
|
import { Context, Recogniser } from './index.js';
|
||||||
import match, { Match } from '../match';
|
import match, { Match } from '../match.js';
|
||||||
|
|
||||||
export default class Ascii implements Recogniser {
|
export default class Ascii implements Recogniser {
|
||||||
name() {
|
name() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Match } from '../match';
|
import { Match } from '../match.js';
|
||||||
|
|
||||||
export interface Recogniser {
|
export interface Recogniser {
|
||||||
match(input: Context): Match | null;
|
match(input: Context): Match | null;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Context, Recogniser } from '.';
|
import { Context, Recogniser } from './index.js';
|
||||||
import match, { Match } from '../match';
|
import match, { Match } from '../match.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a superclass for the individual detectors for
|
* This is a superclass for the individual detectors for
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Context, Recogniser } from '.';
|
import { Context, Recogniser } from './index.js';
|
||||||
import match, { Match } from '../match';
|
import match, { Match } from '../match.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binary search implementation (recursive)
|
* Binary search implementation (recursive)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Context, Recogniser } from '../encoding/index';
|
import { Context, Recogniser } from '../encoding/index.js';
|
||||||
import match, { Match } from '../match';
|
import match, { Match } from '../match.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class recognizes single-byte encodings. Because the encoding scheme is so
|
* This class recognizes single-byte encodings. Because the encoding scheme is so
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Context, Recogniser } from '.';
|
import { Context, Recogniser } from './index.js';
|
||||||
import match, { Match } from '../match';
|
import match, { Match } from '../match.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class matches UTF-16 and UTF-32, both big- and little-endian. The
|
* This class matches UTF-16 and UTF-32, both big- and little-endian. The
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Context, Recogniser } from '.';
|
import { Context, Recogniser } from './index.js';
|
||||||
import match, { Match } from '../match';
|
import match, { Match } from '../match.js';
|
||||||
|
|
||||||
export default class Utf8 implements Recogniser {
|
export default class Utf8 implements Recogniser {
|
||||||
name() {
|
name() {
|
||||||
|
|
36
src/index.ts
36
src/index.ts
|
@ -1,21 +1,21 @@
|
||||||
import { Match } from './match';
|
import { Match } from './match.js';
|
||||||
import { Recogniser, Context } from './encoding';
|
import { Recogniser, Context } from './encoding/index.js';
|
||||||
|
|
||||||
import loadFs from './fs/node';
|
import loadFs from './fs/node.js';
|
||||||
|
|
||||||
import Ascii from './encoding/ascii';
|
import Ascii from './encoding/ascii.js';
|
||||||
import Utf8 from './encoding/utf8';
|
import Utf8 from './encoding/utf8.js';
|
||||||
import * as unicode from './encoding/unicode';
|
import * as unicode from './encoding/unicode.js';
|
||||||
import * as mbcs from './encoding/mbcs';
|
import * as mbcs from './encoding/mbcs.js';
|
||||||
import * as sbcs from './encoding/sbcs';
|
import * as sbcs from './encoding/sbcs.js';
|
||||||
import * as iso2022 from './encoding/iso2022';
|
import * as iso2022 from './encoding/iso2022.js';
|
||||||
|
|
||||||
interface FullOptions {
|
interface FullOptions {
|
||||||
sampleSize: number,
|
sampleSize: number;
|
||||||
offset: number
|
offset: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Options = Partial<FullOptions>
|
export type Options = Partial<FullOptions>;
|
||||||
|
|
||||||
const recognisers: Recogniser[] = [
|
const recognisers: Recogniser[] = [
|
||||||
new Utf8(),
|
new Utf8(),
|
||||||
|
@ -88,9 +88,12 @@ export const analyse = (buffer: Uint8Array): AnalyseResult => {
|
||||||
});
|
});
|
||||||
|
|
||||||
return matches as Match[];
|
return matches as Match[];
|
||||||
}
|
};
|
||||||
|
|
||||||
export const detectFile = (filepath: string, opts: Options = {}): Promise<DetectResult> =>
|
export const detectFile = (
|
||||||
|
filepath: string,
|
||||||
|
opts: Options = {}
|
||||||
|
): Promise<DetectResult> =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
let fd: any;
|
let fd: any;
|
||||||
const fs = loadFs();
|
const fs = loadFs();
|
||||||
|
@ -120,7 +123,10 @@ export const detectFile = (filepath: string, opts: Options = {}): Promise<Detect
|
||||||
fs.readFile(filepath, handler);
|
fs.readFile(filepath, handler);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const detectFileSync = (filepath: string, opts: Options = {}): DetectResult => {
|
export const detectFileSync = (
|
||||||
|
filepath: string,
|
||||||
|
opts: Options = {}
|
||||||
|
): DetectResult => {
|
||||||
const fs = loadFs();
|
const fs = loadFs();
|
||||||
|
|
||||||
if (opts && opts.sampleSize) {
|
if (opts && opts.sampleSize) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Context, Recogniser } from "./encoding";
|
import { Context, Recogniser } from './encoding/index.js';
|
||||||
|
|
||||||
export interface Match {
|
export interface Match {
|
||||||
confidence: number;
|
confidence: number;
|
||||||
|
|
Loading…
Reference in New Issue