-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from hcodes/ts
js → ts
- Loading branch information
Showing
18 changed files
with
5,446 additions
and
1,554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint'], | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Node CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [10.x, 12.x, 14.x] | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: npm install and test | ||
run: | | ||
npm ci | ||
npm test | ||
env: | ||
CI: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
benchmark/ | ||
node_modules/ | ||
libs/ | ||
.nyc_output/ | ||
npm-debug.log |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 Denis Seleznev, [email protected] | ||
Copyright (c) 2020 Denis Seleznev, [email protected] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="node" /> | ||
/** | ||
* Check if a Node.js Buffer or Uint8Array is UTF-8. | ||
*/ | ||
export default function isUtf8(buf?: Buffer | Uint8Array): boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
"use strict"; | ||
/* | ||
https://tools.ietf.org/html/rfc3629 | ||
UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4 | ||
UTF8-1 = %x00-7F | ||
UTF8-2 = %xC2-DF UTF8-tail | ||
UTF8-3 = %xE0 %xA0-BF UTF8-tail | ||
%xE1-EC 2( UTF8-tail ) | ||
%xED %x80-9F UTF8-tail | ||
%xEE-EF 2( UTF8-tail ) | ||
UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) | ||
%xF1-F3 3( UTF8-tail ) | ||
%xF4 %x80-8F 2( UTF8-tail ) | ||
UTF8-tail = %x80-BF | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Check if a Node.js Buffer or Uint8Array is UTF-8. | ||
*/ | ||
function isUtf8(buf) { | ||
if (!buf) { | ||
return false; | ||
} | ||
let i = 0; | ||
const len = buf.length; | ||
while (i < len) { | ||
// UTF8-1 = %x00-7F | ||
if (buf[i] <= 0x7F) { | ||
i++; | ||
continue; | ||
} | ||
// UTF8-2 = %xC2-DF UTF8-tail | ||
if (buf[i] >= 0xC2 && buf[i] <= 0xDF) { | ||
// if(buf[i + 1] >= 0x80 && buf[i + 1] <= 0xBF) { | ||
if (buf[i + 1] >> 6 === 2) { | ||
i += 2; | ||
continue; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
// UTF8-3 = %xE0 %xA0-BF UTF8-tail | ||
// UTF8-3 = %xED %x80-9F UTF8-tail | ||
if (((buf[i] === 0xE0 && buf[i + 1] >= 0xA0 && buf[i + 1] <= 0xBF) || | ||
(buf[i] === 0xED && buf[i + 1] >= 0x80 && buf[i + 1] <= 0x9F)) && buf[i + 2] >> 6 === 2) { | ||
i += 3; | ||
continue; | ||
} | ||
// UTF8-3 = %xE1-EC 2( UTF8-tail ) | ||
// UTF8-3 = %xEE-EF 2( UTF8-tail ) | ||
if (((buf[i] >= 0xE1 && buf[i] <= 0xEC) || | ||
(buf[i] >= 0xEE && buf[i] <= 0xEF)) && | ||
buf[i + 1] >> 6 === 2 && | ||
buf[i + 2] >> 6 === 2) { | ||
i += 3; | ||
continue; | ||
} | ||
// UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) | ||
// %xF1-F3 3( UTF8-tail ) | ||
// %xF4 %x80-8F 2( UTF8-tail ) | ||
if (((buf[i] === 0xF0 && buf[i + 1] >= 0x90 && buf[i + 1] <= 0xBF) || | ||
(buf[i] >= 0xF1 && buf[i] <= 0xF3 && buf[i + 1] >> 6 === 2) || | ||
(buf[i] === 0xF4 && buf[i + 1] >= 0x80 && buf[i + 1] <= 0x8F)) && | ||
buf[i + 2] >> 6 === 2 && | ||
buf[i + 3] >> 6 === 2) { | ||
i += 4; | ||
continue; | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
exports.default = isUtf8; |
Oops, something went wrong.