Skip to content

Commit

Permalink
Merge pull request #77 from near/fix-utils
Browse files Browse the repository at this point in the history
feat: remove unnecesary utils
  • Loading branch information
gagdiez authored Nov 23, 2023
2 parents abe2701 + 4a5482d commit 50f5a18
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 91 deletions.
30 changes: 0 additions & 30 deletions borsh-ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,4 @@ function validate_struct_schema(schema: { [key: string]: Schema }): void {
for (const key in schema) {
validate_schema(schema[key]);
}
}

// utf-8 encode
export function encodeCodePoint(codePoint): number[] {
if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
return [codePoint];
}
let symbol: number[] = [];
if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
symbol = [((codePoint >> 6) & 0x1F) | 0xC0];
}
else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
symbol = [
((codePoint >> 12) & 0x0F) | 0xE0,
createByte(codePoint, 6)
];
}
else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
symbol = [
((codePoint >> 18) & 0x07) | 0xF0,
createByte(codePoint, 12),
createByte(codePoint, 6)
];
}
symbol.push((codePoint & 0x3F) | 0x80);
return symbol;
}

function createByte(codePoint, shift): number {
return ((codePoint >> shift) & 0x3F) | 0x80;
}
1 change: 0 additions & 1 deletion lib/cjs/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export declare class ErrorSchema extends Error {
constructor(schema: Schema, expected: string);
}
export declare function validate_schema(schema: Schema): void;
export declare function encodeCodePoint(codePoint: any): number[];
31 changes: 1 addition & 30 deletions lib/cjs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var __extends = (this && this.__extends) || (function () {
};
})();
exports.__esModule = true;
exports.encodeCodePoint = exports.validate_schema = exports.ErrorSchema = exports.expect_enum = exports.expect_same_size = exports.expect_bigint = exports.expect_type = exports.isArrayLike = void 0;
exports.validate_schema = exports.ErrorSchema = exports.expect_enum = exports.expect_same_size = exports.expect_bigint = exports.expect_type = exports.isArrayLike = void 0;
var types_js_1 = require("./types.js");
function isArrayLike(value) {
// source: https://stackoverflow.com/questions/24048547/checking-if-an-object-is-array-like
Expand Down Expand Up @@ -132,32 +132,3 @@ function validate_struct_schema(schema) {
validate_schema(schema[key]);
}
}
// utf-8 encode
function encodeCodePoint(codePoint) {
if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
return [codePoint];
}
var symbol = [];
if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
symbol = [((codePoint >> 6) & 0x1F) | 0xC0];
}
else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
symbol = [
((codePoint >> 12) & 0x0F) | 0xE0,
createByte(codePoint, 6)
];
}
else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
symbol = [
((codePoint >> 18) & 0x07) | 0xF0,
createByte(codePoint, 12),
createByte(codePoint, 6)
];
}
symbol.push((codePoint & 0x3F) | 0x80);
return symbol;
}
exports.encodeCodePoint = encodeCodePoint;
function createByte(codePoint, shift) {
return ((codePoint >> shift) & 0x3F) | 0x80;
}
1 change: 0 additions & 1 deletion lib/esm/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export declare class ErrorSchema extends Error {
constructor(schema: Schema, expected: string);
}
export declare function validate_schema(schema: Schema): void;
export declare function encodeCodePoint(codePoint: any): number[];
28 changes: 0 additions & 28 deletions lib/esm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,3 @@ function validate_struct_schema(schema) {
validate_schema(schema[key]);
}
}
// utf-8 encode
export function encodeCodePoint(codePoint) {
if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
return [codePoint];
}
var symbol = [];
if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
symbol = [((codePoint >> 6) & 0x1F) | 0xC0];
}
else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
symbol = [
((codePoint >> 12) & 0x0F) | 0xE0,
createByte(codePoint, 6)
];
}
else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
symbol = [
((codePoint >> 18) & 0x07) | 0xF0,
createByte(codePoint, 12),
createByte(codePoint, 6)
];
}
symbol.push((codePoint & 0x3F) | 0x80);
return symbol;
}
function createByte(codePoint, shift) {
return ((codePoint >> shift) & 0x3F) | 0x80;
}
1 change: 0 additions & 1 deletion lib/types/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export declare class ErrorSchema extends Error {
constructor(schema: Schema, expected: string);
}
export declare function validate_schema(schema: Schema): void;
export declare function encodeCodePoint(codePoint: any): number[];

0 comments on commit 50f5a18

Please sign in to comment.