Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: runk/node-chardet
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.5.0
Choose a base ref
...
head repository: runk/node-chardet
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.5.1
Choose a head ref
  • 12 commits
  • 6 files changed
  • 2 contributors

Commits on Nov 1, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ab6f6f7 View commit details
  2. Copy the full SHA
    ef317d2 View commit details

Commits on Nov 2, 2022

  1. Copy the full SHA
    c8c3a8a View commit details

Commits on Dec 17, 2022

  1. Merge pull request #67 from runk/renovate/actions-setup-node-3.x

    chore(deps): update actions/setup-node action to v3
    Dmitry Shirokov authored Dec 17, 2022
    Copy the full SHA
    f8f5020 View commit details
  2. Merge pull request #66 from runk/renovate/actions-checkout-3.x

    chore(deps): update actions/checkout action to v3
    Dmitry Shirokov authored Dec 17, 2022
    Copy the full SHA
    44cc4f8 View commit details
  3. Copy the full SHA
    e1a408e View commit details
  4. remote node@12 from tests

    Dmitry Shirokov committed Dec 17, 2022
    Copy the full SHA
    2c6d1fa View commit details
  5. Merge pull request #70 from runk/renovate/major-jest-monorepo

    chore(deps): update jest monorepo to v29 (major)
    Dmitry Shirokov authored Dec 17, 2022
    Copy the full SHA
    4ad3956 View commit details

Commits on Jan 5, 2023

  1. patch: Export AnalyseResult and DetectResult types

    Dmitry Shirokov committed Jan 5, 2023
    Copy the full SHA
    927d5c6 View commit details
  2. Merge pull request #72 from runk/export-result-types

    patch: Export AnalyseResult and DetectResult types
    Dmitry Shirokov authored Jan 5, 2023
    Copy the full SHA
    dfa504f View commit details
  3. fix(types): Export AnalyseResult and DetectResult types

    Dmitry Shirokov committed Jan 5, 2023
    Copy the full SHA
    1472a8b View commit details
  4. Merge pull request #73 from runk/trigger-release

    fix(types): Export AnalyseResult and DetectResult types
    Dmitry Shirokov authored Jan 5, 2023
    Copy the full SHA
    fbef681 View commit details
Showing with 14 additions and 16 deletions.
  1. +0 −3 .eslintignore
  2. +3 −3 .github/workflows/build.yml
  3. +2 −2 .github/workflows/release.yml
  4. +1 −1 LICENSE
  5. +4 −4 package.json
  6. +4 −3 src/index.ts
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -12,12 +12,12 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 16.x, 18.x]
node-version: [14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm i
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -9,11 +9,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 14
- name: Install dependencies
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2022 Dmitry Shirokov
Copyright (C) 2023 Dmitry Shirokov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -33,12 +33,12 @@
"test": "test"
},
"devDependencies": {
"@types/jest": "^26.0.14",
"@types/node": "^14.11.2",
"jest": "^26.4.2",
"@types/jest": "^29.0.0",
"@types/node": "^18.0.0",
"jest": "^29.0.0",
"prettier": "^2.7.1",
"semantic-release": "^19.0.5",
"ts-jest": "^26.4.0",
"ts-jest": "^29.0.0",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
},
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ interface FullOptions {
offset: number
}

type Options = Partial<FullOptions>
export type Options = Partial<FullOptions>

const recognisers: Recogniser[] = [
new Utf8(),
@@ -42,14 +42,15 @@ const recognisers: Recogniser[] = [
new sbcs.KOI8_R(),
];

type DetectResult = Match[] | string | null;
export type AnalyseResult = Match[];
export type DetectResult = string | null;

export const detect = (buffer: Uint8Array): string | null => {
const matches: Match[] = analyse(buffer);
return matches.length > 0 ? matches[0].name : null;
};

export const analyse = (buffer: Uint8Array): Match[] => {
export const analyse = (buffer: Uint8Array): AnalyseResult => {
// Tally up the byte occurrence statistics.
const byteStats = [];
for (let i = 0; i < 256; i++) byteStats[i] = 0;