include node_modules so release .zip is deployable

This commit is contained in:
2023-11-24 17:44:25 -05:00
parent 6c86cfe5d2
commit 8b11c41267
8963 changed files with 874175 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
Rafael da Silva Rocha <rocha.rafaelsilva@gmail.com>
+19
View File
@@ -0,0 +1,19 @@
# CHANGELOG
## 1.0.0 - 2019-12-31
- New package structure:
* dist file is "./dist/utf8-buffer.js", a UMD served as "main"
* ES6 source is "./index.js", served as "module"
## 0.2.0 (2018-08-05)
- unpack(buffer, start, end) API change: end now is non-inclusive
## 0.1.0 (2018-07-27)
- pack(str):Uint8Array updated to pack(str, buffer, index=0):number
- *buffer* is the buffer you are writing to (ideally Uint8Array, but will work the same with Array or any Array-like object).
- *index* is a optional param with the buffer index to start writing. Assumes zero by default.
- The return value is a *number*, the next index to write in the array.
- unpack(buffer, index, len) updated to unpack(buffer, start, end)
- *start* is the buffer index to start reading.
- *end* is the buffer index to end reading.
- works in IE8+.
+20
View File
@@ -0,0 +1,20 @@
Copyright (c) 2018 Rafael da Silva Rocha.
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:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+105
View File
@@ -0,0 +1,105 @@
# utf8-buffer
ES6 module to encode and decode UTF-8 strings.
Copyright (c) 2018-2019 Rafael da Silva Rocha.
https://github.com/rochars/utf8-buffer
[![NPM version](https://img.shields.io/npm/v/utf8-buffer.svg?style=for-the-badge)](https://www.npmjs.com/package/utf8-buffer) [![Docs](https://img.shields.io/badge/docs-online-blue.svg?style=for-the-badge)](https://rochars.github.io/utf8-buffer/docs/index.html) [![Tests](https://img.shields.io/badge/tests-online-blue.svg?style=for-the-badge)](https://rochars.github.io/utf8-buffer/test/dist/browser.html)
[![Codecov](https://img.shields.io/codecov/c/github/rochars/utf8-buffer.svg?style=flat-square)](https://codecov.io/gh/rochars/utf8-buffer) [![Unix Build](https://img.shields.io/travis/rochars/utf8-buffer.svg?style=flat-square)](https://travis-ci.org/rochars/utf8-buffer) [![Windows Build](https://img.shields.io/appveyor/ci/rochars/utf8-buffer.svg?style=flat-square&logo=appveyor)](https://ci.appveyor.com/project/rochars/utf8-buffer) [![Scrutinizer](https://img.shields.io/scrutinizer/g/rochars/utf8-buffer.svg?style=flat-square&logo=scrutinizer)](https://scrutinizer-ci.com/g/rochars/utf8-buffer/)
**utf8-buffer** is a ES6 module to encode and decode UTF-8 strings.
## Install
```
npm install utf8-buffer
```
## Use
### Browser
Use the **utf8-buffer.js** file in the */dist* folder:
```html
<script src="./dist/utf8-buffer.js"></script>
```
Or load it from the [jsDelivr](https://cdn.jsdelivr.net/npm/utf8-buffer) CDN:
```html
<script src="https://cdn.jsdelivr.net/npm/utf8-buffer"></script>
```
Or load it from [unpkg](https://unpkg.com/utf8-buffer):
```html
<script src="https://unpkg.com/utf8-buffer"></script>
```
### Node
```javascript
const utf8Buffer = require('utf8-buffer');
```
Or **import** just what you need:
```javascript
import {pack, unpack} from 'utf8-buffer';
```
## About
Only UTF-8 strings with a max of 4 bytes per character are supported. **BOM** is kept untouched. Invalid characters are replaced with *Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD)*.
## API
```javascript
/**
* Read a string of UTF-8 characters from a byte buffer.
* Invalid characters are replaced with 'REPLACEMENT CHARACTER' (U+FFFD).
* @see https://encoding.spec.whatwg.org/#the-encoding
* @see https://stackoverflow.com/a/34926911
* @param {!Uint8Array|!Array<number>} buffer A byte buffer.
* @param {number=} start The buffer index to start reading.
* @param {?number=} end The buffer index to stop reading.
* Assumes the buffer length if undefined.
* @return {string}
*/
export function unpack(buffer, start=0, end=buffer.length) {}
/**
* Write a string of UTF-8 characters to a byte buffer.
* @see https://encoding.spec.whatwg.org/#utf-8-encoder
* @param {string} str The string to pack.
* @param {!Uint8Array|!Array<number>} buffer The buffer to pack the string to.
* @param {number=} index The buffer index to start writing.
* @return {number} The next index to write in the buffer.
*/
export function pack(str, buffer, index=0) {}
```
## Contributing
**utf8-buffer** welcomes all contributions from anyone willing to work in good faith with other contributors and the community. No contribution is too small and all contributions are valued.
See [CONTRIBUTING.md](https://github.com/rochars/utf8-buffer/blob/master/CONTRIBUTING.md) for details.
### Style guide
**utf8-buffer** code should follow the Google JavaScript Style Guide:
https://google.github.io/styleguide/jsguide.html
### Code of conduct
This project is bound by a code of conduct: The [Contributor Covenant, version 1.4](https://github.com/rochars/utf8-buffer/blob/master/CODE_OF_CONDUCT.md), also available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
## LICENSE
Copyright (c) 2018-2019 Rafael da Silva Rocha.
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:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+7
View File
@@ -0,0 +1,7 @@
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.checkStringArgs=function(a,b,c){if(null==a)throw new TypeError("The 'this' value for String.prototype."+c+" must not be null or undefined");if(b instanceof RegExp)throw new TypeError("First argument to String.prototype."+c+" must not be a regular expression");return a+""};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(a,b,c,d){if(b){c=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var h=a[d];h in c||(c[h]={});c=c[h]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:b})}};
$jscomp.polyfill("String.prototype.codePointAt",function(a){return a?a:function(b){var c=$jscomp.checkStringArgs(this,null,"codePointAt"),a=c.length;b=Number(b)||0;if(0<=b&&b<a){b|=0;var h=c.charCodeAt(b);if(55296>h||56319<h||b+1===a)return h;b=c.charCodeAt(b+1);return 56320>b||57343<b?h:1024*(h-55296)+b+9216}}},"es6","es3");
(function(a,b){"object"===typeof exports&&"undefined"!==typeof module?b(exports):"function"===typeof define&&define.amd?define(["exports"],b):(a=a||self,b(a.UTF8Buffer={}))})(this,function(a){a.pack=function(b,a,d){d=void 0===d?0:d;for(var c=0,k=b.length;c<k;c++){var f=b.codePointAt(c);if(128>f)a[d]=f,d++;else{var g=0,e=0;2047>=f?(g=1,e=192):65535>=f?(g=2,e=224):1114111>=f&&(g=3,e=240,c++);a[d]=(f>>6*g)+e;for(d++;0<g;)a[d]=128|f>>6*(g-1)&63,d++,g--}}return d};a.unpack=function(b,a,d){d=void 0===d?
b.length:d;var c="";for(a=void 0===a?0:a;a<d;){var k=128,f=191,g=!1,e=b[a++];if(0<=e&&127>=e)c+=String.fromCharCode(e);else{var l=0;194<=e&&223>=e?l=1:224<=e&&239>=e?(l=2,224===b[a]&&(k=160),237===b[a]&&(f=159)):240<=e&&244>=e?(l=3,240===b[a]&&(k=144),244===b[a]&&(f=143)):g=!0;e&=(1<<8-l-1)-1;for(var m=0;m<l;m++){if(b[a]<k||b[a]>f)g=!0;e=e<<6|b[a]&63;a++}g?c+=String.fromCharCode(65533):65535>=e?c+=String.fromCharCode(e):(e-=65536,c+=String.fromCharCode((e>>10&1023)+55296,(e&1023)+56320))}}return c};
Object.defineProperty(a,"__esModule",{value:!0})});
+52
View File
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2018-2019 Rafael da Silva Rocha.
*
* 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:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @fileoverview Externs for utf8-buffer 1.0.0
* @see https://github.com/rochars/utf8-buffer
* @externs
*/
/**
* Read a string of UTF-8 characters from a byte buffer.
* Invalid characters are replaced with 'REPLACEMENT CHARACTER' (U+FFFD).
* @see https://encoding.spec.whatwg.org/#the-encoding
* @see https://stackoverflow.com/a/34926911
* @param {!Uint8Array|!Array<number>} buffer A byte buffer.
* @param {number=} start The buffer index to start reading.
* @param {?number=} end The buffer index to stop reading.
* If end is null will read until the end of the buffer.
* @return {string}
*/
function unpack(buffer, start=0, end=null) {}
/**
* Write a string of UTF-8 characters to a byte buffer.
* @see https://encoding.spec.whatwg.org/#utf-8-encoder
* @param {string} str The string to pack.
* @param {!Uint8Array|!Array<number>} buffer The buffer to pack the string to.
* @param {number=} index The buffer index to start writing.
* @return {number} The next index to write in the buffer.
*/
function pack(str, buffer, index=0) {}
+33
View File
@@ -0,0 +1,33 @@
// Type definitions for utf8-buffer 1.0.0
// Project: https://github.com/rochars/byte-data
// Definitions by: Rafael da Silva Rocha <https://github.com/rochars>
// Definitions: https://github.com/rochars/utf8-buffer
/**
* Read a string of UTF-8 characters from a byte buffer.
* Invalid characters are replaced with 'REPLACEMENT CHARACTER' (U+FFFD).
* @see https://encoding.spec.whatwg.org/#the-encoding
* @see https://stackoverflow.com/a/34926911
* @param {!Uint8Array|!Array<number>} buffer A byte buffer.
* @param {number=} start The buffer index to start reading.
* @param {?number=} end The buffer index to stop reading.
* Assumes the buffer length if undefined.
* @return {string}
*/
export function unpack(
buffer: Uint8Array|number[],
start: number,
end?: number): string;
/**
* Write a string of UTF-8 characters to a byte buffer.
* @see https://encoding.spec.whatwg.org/#utf-8-encoder
* @param {string} str The string to pack.
* @param {!Uint8Array|!Array<number>} buffer The buffer to pack the string to.
* @param {number=} index The buffer index to start writing.
* @return {number} The next index to write in the buffer.
*/
export function pack(
str: string,
buffer: Uint8Array|number[],
index?: number): number;
+148
View File
@@ -0,0 +1,148 @@
/*
* Copyright (c) 2018 Rafael da Silva Rocha.
*
* 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:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @fileoverview Functions to serialize and deserialize UTF-8 strings.
* @see https://github.com/rochars/utf8-buffer
* @see https://encoding.spec.whatwg.org/#the-encoding
* @see https://encoding.spec.whatwg.org/#utf-8-encoder
*/
/** @module utf8-buffer */
/**
* Read a string of UTF-8 characters from a byte buffer.
* Invalid characters are replaced with 'REPLACEMENT CHARACTER' (U+FFFD).
* @see https://encoding.spec.whatwg.org/#the-encoding
* @see https://stackoverflow.com/a/34926911
* @param {!Uint8Array|!Array<number>} buffer A byte buffer.
* @param {number=} start The buffer index to start reading.
* @param {?number=} end The buffer index to stop reading.
* Assumes the buffer length if undefined.
* @return {string}
*/
export function unpack(buffer, start=0, end=buffer.length) {
/** @type {string} */
let str = '';
for(let index = start; index < end;) {
/** @type {number} */
let lowerBoundary = 0x80;
/** @type {number} */
let upperBoundary = 0xBF;
/** @type {boolean} */
let replace = false;
/** @type {number} */
let charCode = buffer[index++];
if (charCode >= 0x00 && charCode <= 0x7F) {
str += String.fromCharCode(charCode);
} else {
/** @type {number} */
let count = 0;
if (charCode >= 0xC2 && charCode <= 0xDF) {
count = 1;
} else if (charCode >= 0xE0 && charCode <= 0xEF ) {
count = 2;
if (buffer[index] === 0xE0) {
lowerBoundary = 0xA0;
}
if (buffer[index] === 0xED) {
upperBoundary = 0x9F;
}
} else if (charCode >= 0xF0 && charCode <= 0xF4 ) {
count = 3;
if (buffer[index] === 0xF0) {
lowerBoundary = 0x90;
}
if (buffer[index] === 0xF4) {
upperBoundary = 0x8F;
}
} else {
replace = true;
}
charCode = charCode & (1 << (8 - count - 1)) - 1;
for (let i = 0; i < count; i++) {
if (buffer[index] < lowerBoundary || buffer[index] > upperBoundary) {
replace = true;
}
charCode = (charCode << 6) | (buffer[index] & 0x3f);
index++;
}
if (replace) {
str += String.fromCharCode(0xFFFD);
}
else if (charCode <= 0xffff) {
str += String.fromCharCode(charCode);
} else {
charCode -= 0x10000;
str += String.fromCharCode(
((charCode >> 10) & 0x3ff) + 0xd800,
(charCode & 0x3ff) + 0xdc00);
}
}
}
return str;
}
/**
* Write a string of UTF-8 characters to a byte buffer.
* @see https://encoding.spec.whatwg.org/#utf-8-encoder
* @param {string} str The string to pack.
* @param {!Uint8Array|!Array<number>} buffer The buffer to pack the string to.
* @param {number=} index The buffer index to start writing.
* @return {number} The next index to write in the buffer.
*/
export function pack(str, buffer, index=0) {
for (let i = 0, len = str.length; i < len; i++) {
/** @type {number} */
let codePoint = str.codePointAt(i);
if (codePoint < 128) {
buffer[index] = codePoint;
index++;
} else {
/** @type {number} */
let count = 0;
/** @type {number} */
let offset = 0;
if (codePoint <= 0x07FF) {
count = 1;
offset = 0xC0;
} else if(codePoint <= 0xFFFF) {
count = 2;
offset = 0xE0;
} else if(codePoint <= 0x10FFFF) {
count = 3;
offset = 0xF0;
i++;
}
buffer[index] = (codePoint >> (6 * count)) + offset;
index++;
while (count > 0) {
buffer[index] = 0x80 | (codePoint >> (6 * (count - 1)) & 0x3F);
index++;
count--;
}
}
}
return index;
}
+72
View File
@@ -0,0 +1,72 @@
{
"name": "utf8-buffer",
"version": "1.0.0",
"description": "ES6 module to encode and decode UTF-8 strings.",
"homepage": "https://github.com/rochars/utf8-buffer",
"author": "Rafael da Silva Rocha <rocha.rafaelsilva@gmail.com>",
"license": "MIT",
"main": "./dist/utf8-buffer.js",
"module": "./index.js",
"types": "./index.d.ts",
"engines": {
"node": ">=8"
},
"keywords": [
"byte",
"buffer",
"binary",
"parser",
"ASCII",
"UTF-8",
"string",
"pack",
"unpack",
"ES6"
],
"repository": {
"type": "git",
"url": "git://github.com/rochars/utf8-buffer.git"
},
"bugs": {
"url": "https://github.com/rochars/utf8-buffer/issues"
},
"directories": {
"dist": "dist",
"externs": "externs"
},
"files": [
"dist",
"externs",
"index.js",
"index.d.ts",
"LICENSE",
"AUTHORS.md",
"CHANGELOG.md",
"README.md"
],
"scripts": {
"lint": "jshint index.js externs",
"test": "nyc ./node_modules/mocha/bin/_mocha test/src --recursive -R dot",
"test-umd": "node ./node_modules/mocha/bin/_mocha test/src --umd --recursive -R dot",
"test-tsc": "tsc ./test/dist/TypeScript/main.ts && node -r esm ./test/dist/TypeScript/main.js",
"test-dist": "npm run test-umd && npm run test-tsc",
"pack": "npm run test && rollup -c && npm run test-dist",
"doc": "./node_modules/.bin/jsdoc -c .jsdocrc index.js -d docs -r README.md -t node_modules/docdash",
"build": "npm run lint && npm run pack && npm run doc",
"coverage": "nyc report --reporter=lcov > coverage.lcov && codecov"
},
"devDependencies": {
"@ampproject/rollup-plugin-closure-compiler": "^0.13.0",
"codecov": "^3.6.1",
"docdash": "^1.1.1",
"esm": "^3.2.25",
"jsdoc": "^3.6.3",
"jshint": "^2.10.3",
"mocha": "^6.2.2",
"mocha-lcov-reporter": "^1.3.0",
"nyc": "^14.1.1",
"rollup": "^1.27.14",
"typescript": "^3.7.4"
},
"dependencies": {}
}