diff --git a/.gitignore b/.gitignore index 76add87..04c01ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -node_modules -dist \ No newline at end of file +node_modules/ +dist/ \ No newline at end of file diff --git a/README.md b/README.md index 3155182..8123d10 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ # long-ts -An alternative to [https://github.com/dcodeIO/long.js](long.js) with support for ESM, CJS, UMD and [https://github.com/developit/microbundle#modern](Modern Mode). It's written in TypeScript and thus houses it's own type declarations. The only notable differences between long-ts and long.js are the removal of `Long.isLong()` in favor of using `instanceof`. All aliased shorthand methods are also removed. +An alternative to [long.js](https://github.com/dcodeIO/long.js) with support for ESM, CJS, UMD and [Modern Mode](https://github.com/developit/microbundle#modern). It's written in TypeScript and thus houses it's own type declarations. + +long-ts and long.js differences: + +- Removed `Long.isLong()` in favor of using `instanceof`. +- Removed all aliased shorthand methods like `eq` and `shr` and more. +- Using named export `import { Long } from 'long-ts'` instead of `const Long = require('long.js')` ## Installation @@ -20,4 +26,25 @@ console.log(longVal.toString()); ## Documentation -... +https://hornta.github.io/long-ts/modules.html + +## Building + +`npm run build` will also build the documentation in `/docs` + +``` +npm install +npm run build +``` + +Running tests: + +``` +npm run test +``` + +Running linter: + +``` +npm run lint +``` diff --git a/docs/assets/highlight.css b/docs/assets/highlight.css index a13094d..1fac3df 100644 --- a/docs/assets/highlight.css +++ b/docs/assets/highlight.css @@ -1,22 +1,78 @@ :root { + --light-hl-0: #001080; + --dark-hl-0: #9CDCFE; + --light-hl-1: #000000; + --dark-hl-1: #D4D4D4; + --light-hl-2: #AF00DB; + --dark-hl-2: #C586C0; + --light-hl-3: #A31515; + --dark-hl-3: #CE9178; + --light-hl-4: #0000FF; + --dark-hl-4: #569CD6; + --light-hl-5: #0070C1; + --dark-hl-5: #4FC1FF; + --light-hl-6: #795E26; + --dark-hl-6: #DCDCAA; + --light-hl-7: #098658; + --dark-hl-7: #B5CEA8; --light-code-background: #FFFFFF; --dark-code-background: #1E1E1E; } @media (prefers-color-scheme: light) { :root { + --hl-0: var(--light-hl-0); + --hl-1: var(--light-hl-1); + --hl-2: var(--light-hl-2); + --hl-3: var(--light-hl-3); + --hl-4: var(--light-hl-4); + --hl-5: var(--light-hl-5); + --hl-6: var(--light-hl-6); + --hl-7: var(--light-hl-7); --code-background: var(--light-code-background); } } @media (prefers-color-scheme: dark) { :root { + --hl-0: var(--dark-hl-0); + --hl-1: var(--dark-hl-1); + --hl-2: var(--dark-hl-2); + --hl-3: var(--dark-hl-3); + --hl-4: var(--dark-hl-4); + --hl-5: var(--dark-hl-5); + --hl-6: var(--dark-hl-6); + --hl-7: var(--dark-hl-7); --code-background: var(--dark-code-background); } } body.light { + --hl-0: var(--light-hl-0); + --hl-1: var(--light-hl-1); + --hl-2: var(--light-hl-2); + --hl-3: var(--light-hl-3); + --hl-4: var(--light-hl-4); + --hl-5: var(--light-hl-5); + --hl-6: var(--light-hl-6); + --hl-7: var(--light-hl-7); --code-background: var(--light-code-background); } body.dark { + --hl-0: var(--dark-hl-0); + --hl-1: var(--dark-hl-1); + --hl-2: var(--dark-hl-2); + --hl-3: var(--dark-hl-3); + --hl-4: var(--dark-hl-4); + --hl-5: var(--dark-hl-5); + --hl-6: var(--dark-hl-6); + --hl-7: var(--dark-hl-7); --code-background: var(--dark-code-background); } +.hl-0 { color: var(--hl-0); } +.hl-1 { color: var(--hl-1); } +.hl-2 { color: var(--hl-2); } +.hl-3 { color: var(--hl-3); } +.hl-4 { color: var(--hl-4); } +.hl-5 { color: var(--hl-5); } +.hl-6 { color: var(--hl-6); } +.hl-7 { color: var(--hl-7); } pre, code { background: var(--code-background); } diff --git a/docs/classes/Long.html b/docs/classes/Long.html index d9d159c..4704d64 100644 --- a/docs/classes/Long.html +++ b/docs/classes/Long.html @@ -1,65 +1,65 @@ -Long | long-ts
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Long

Hierarchy

  • Long

Index

Constructors

constructor

  • new Long(low: number, high: number, unsigned?: boolean): Long
  • Parameters

    • low: number
    • high: number
    • unsigned: boolean = false

    Returns Long

Properties

high

high: number

low

low: number

unsigned

unsigned: boolean

Static Readonly MAX_UNSIGNED_VALUE

MAX_UNSIGNED_VALUE: Long = ...

Static Readonly MAX_VALUE

MAX_VALUE: Long = ...

Static Readonly MIN_VALUE

MIN_VALUE: Long = ...

Static Readonly NEG_ONE

NEG_ONE: Long = ...

Static Readonly ONE

ONE: Long = ...

Static Readonly UONE

UONE: Long = ...

Static Readonly UZERO

UZERO: Long = ...

Static Readonly ZERO

ZERO: Long = ...

Methods

add

  • add(addend: string | number | Long): Long
  • +Long | long-ts
    Options
    All
    • Public
    • Public/Protected
    • All
    Menu

    Class Long

    Hierarchy

    • Long

    Index

    Constructors

    constructor

    • new Long(low: number, high: number, unsigned?: boolean): Long
    • Parameters

      • low: number
      • high: number
      • unsigned: boolean = false

      Returns Long

    Properties

    high

    high: number

    low

    low: number

    unsigned

    unsigned: boolean

    Static Readonly MAX_UNSIGNED_VALUE

    MAX_UNSIGNED_VALUE: Long = ...

    Static Readonly MAX_VALUE

    MAX_VALUE: Long = ...

    Static Readonly MIN_VALUE

    MIN_VALUE: Long = ...

    Static Readonly NEG_ONE

    NEG_ONE: Long = ...

    Static Readonly ONE

    ONE: Long = ...

    Static Readonly UONE

    UONE: Long = ...

    Static Readonly UZERO

    UZERO: Long = ...

    Static Readonly ZERO

    ZERO: Long = ...

    Methods

    add

    • add(addend: string | number | Long): Long
    • Returns the sum of this and the specified Long.

      -

      Parameters

      • addend: string | number | Long

      Returns Long

    and

    • and(other: string | number | Long): Long
    • +

      Parameters

      • addend: string | number | Long

      Returns Long

    and

    • and(other: string | number | Long): Long
    • Returns the bitwise AND of this Long and the specified.

      -

      Parameters

      • other: string | number | Long

      Returns Long

    compare

    • compare(other: string | number | Long): 0 | 1 | -1
    • +

      Parameters

      • other: string | number | Long

      Returns Long

    compare

    • compare(other: string | number | Long): 0 | 1 | -1
    • Compares this Long's value with the specified's.

      -

      Parameters

      • other: string | number | Long

      Returns 0 | 1 | -1

    divide

    • divide(divisor: string | number | Long): Long
    • +

      Parameters

      • other: string | number | Long

      Returns 0 | 1 | -1

    divide

    • divide(divisor: string | number | Long): Long
    • Returns this Long divided by the specified. The result is signed if this Long is signed or unsigned if this Long is unsigned.

      -

      Parameters

      • divisor: string | number | Long

      Returns Long

    equals

    • equals(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    getHighBits

    • getHighBits(): number
    • +

      Parameters

      • divisor: string | number | Long

      Returns Long

    equals

    • equals(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    getHighBits

    • getHighBits(): number
    • Gets the high 32 bits as a signed integer.

      -

      Returns number

    getHighBitsUnsigned

    • getHighBitsUnsigned(): number
    • +

      Returns number

    getHighBitsUnsigned

    • getHighBitsUnsigned(): number
    • Gets the high 32 bits as an unsigned integer.

      -

      Returns number

    getLowBits

    • getLowBits(): number
    • +

      Returns number

    getLowBits

    • getLowBits(): number
    • Gets the low 32 bits as a signed integer.

      -

      Returns number

    getLowBitsUnsigned

    • getLowBitsUnsigned(): number
    • +

      Returns number

    getLowBitsUnsigned

    • getLowBitsUnsigned(): number
    • Gets the low 32 bits as an unsigned integer.

      -

      Returns number

    getNumBitsAbs

    • getNumBitsAbs(): number
    • +

      Returns number

    getNumBitsAbs

    • getNumBitsAbs(): number
    • Gets the number of bits needed to represent the absolute value of this Long.

      -

      Returns number

    greaterThan

    • greaterThan(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    greaterThanOrEqual

    • greaterThanOrEqual(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    isEven

    • isEven(): boolean
    • Returns boolean

    isNegative

    • isNegative(): boolean
    • Returns boolean

    isOdd

    • isOdd(): boolean
    • Returns boolean

    isPositive

    • isPositive(): boolean
    • Returns boolean

    isZero

    • isZero(): boolean
    • Returns boolean

    lessThan

    • lessThan(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    lessThanOrEqual

    • lessThanOrEqual(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    modulo

    • modulo(divisor: string | number | Long): Long
    • +

      Returns number

    greaterThan

    • greaterThan(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    greaterThanOrEqual

    • greaterThanOrEqual(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    isEven

    • isEven(): boolean

    isNegative

    • isNegative(): boolean

    isOdd

    • isOdd(): boolean

    isPositive

    • isPositive(): boolean

    isZero

    • isZero(): boolean

    lessThan

    • lessThan(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    lessThanOrEqual

    • lessThanOrEqual(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    modulo

    • modulo(divisor: string | number | Long): Long
    • Returns this Long modulo the specified.

      -

      Parameters

      • divisor: string | number | Long

      Returns Long

    multiply

    • multiply(multiplier: string | number | Long): Long
    • +

      Parameters

      • divisor: string | number | Long

      Returns Long

    multiply

    • multiply(multiplier: string | number | Long): Long
    • Returns the product of this and the specified Long.

      -

      Parameters

      • multiplier: string | number | Long

      Returns Long

    negate

    • +

      Parameters

      • multiplier: string | number | Long

      Returns Long

    negate

    not

    • +

      Returns Long

    not

    notEquals

    • notEquals(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    or

    • +

      Returns Long

    notEquals

    • notEquals(other: string | number | Long): boolean
    • Parameters

      • other: string | number | Long

      Returns boolean

    or

    • Returns the bitwise OR of this Long and the specified.

      -

      Parameters

      • other: string | number | Long

      Returns Long

    rotateLeft

    • rotateLeft(numBits: number | Long): Long
    • +

      Parameters

      • other: string | number | Long

      Returns Long

    rotateLeft

    • rotateLeft(numBits: number | Long): Long
    • Returns this Long with bits rotated to the left by the given amount.

      -

      Parameters

      • numBits: number | Long

      Returns Long

    rotateRight

    • rotateRight(numBits: number | Long): Long
    • +

      Parameters

      • numBits: number | Long

      Returns Long

    rotateRight

    • rotateRight(numBits: number | Long): Long
    • Returns this Long with bits rotated to the right by the given amount.

      -

      Parameters

      • numBits: number | Long

      Returns Long

    shiftLeft

    • +

      Parameters

      • numBits: number | Long

      Returns Long

    shiftLeft

    • Returns this Long with bits shifted to the left by the given amount.

      -

      Parameters

      • numBits: number | Long

      Returns Long

    shiftRight

    • shiftRight(numBits: number | Long): Long
    • +

      Parameters

      • numBits: number | Long

      Returns Long

    shiftRight

    • shiftRight(numBits: number | Long): Long
    • Returns this Long with bits arithmetically shifted to the right by the given amount.

      -

      Parameters

      • numBits: number | Long

      Returns Long

    shiftRightUnsigned

    • shiftRightUnsigned(numBits: number | Long): Long
    • +

      Parameters

      • numBits: number | Long

      Returns Long

    shiftRightUnsigned

    • shiftRightUnsigned(numBits: number | Long): Long
    • Returns this Long with bits logically shifted to the right by the given amount.

      -

      Parameters

      • numBits: number | Long

      Returns Long

    subtract

    • subtract(subtrahend: string | number | Long): Long
    • +

      Parameters

      • numBits: number | Long

      Returns Long

    subtract

    • subtract(subtrahend: string | number | Long): Long
    • Returns the difference of this and the specified Long.

      -

      Parameters

      • subtrahend: string | number | Long

      Returns Long

    toBytes

    • toBytes(le?: boolean): number[]
    • +

      Parameters

      • subtrahend: string | number | Long

      Returns Long

    toBytes

    • toBytes(le?: boolean): number[]
    • Converts this Long to its byte representation.

      -

      Parameters

      • Optional le: boolean

      Returns number[]

    toBytesBE

    • toBytesBE(): number[]
    • +

      Parameters

      • Optional le: boolean

      Returns number[]

    toBytesBE

    • toBytesBE(): number[]
    • Converts this Long to its big endian byte representation.

      -

      Returns number[]

    toBytesLE

    • toBytesLE(): number[]
    • +

      Returns number[]

    toBytesLE

    • toBytesLE(): number[]
    • Converts this Long to its little endian byte representation.

      -

      Returns number[]

    toInt

    • toInt(): number
    • +

      Returns number[]

    toInt

    • toInt(): number
    • Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.

      -

      Returns number

    toNumber

    • toNumber(): number
    • +

      Returns number

    toNumber

    • toNumber(): number
    • Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).

      -

      Returns number

    toSigned

    • +

      Returns number

    toSigned

    toString

    • toString(radix?: number): string
    • +

      Returns Long

    toString

    • toString(radix?: number): string
    • Converts the Long to a string written in the specified radix.

      -

      Parameters

      • radix: number = 10

      Returns string

    toUnsigned

    • +

      Parameters

      • radix: number = 10

      Returns string

    toUnsigned

    xor

    • xor(other: string | number | Long): Long
    • +

      Returns Long

    xor

    • xor(other: string | number | Long): Long
    • Returns the bitwise XOR of this Long and the given one.

      -

      Parameters

      • other: string | number | Long

      Returns Long

    Static fromBits

    • fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long
    • Parameters

      • lowBits: number
      • highBits: number
      • Optional unsigned: boolean

      Returns Long

    Static fromBytes

    • fromBytes(bytes: number[], unsigned?: boolean, le?: boolean): Long
    • +

      Parameters

      • other: string | number | Long

      Returns Long

    Static fromBits

    • fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long
    • Parameters

      • lowBits: number
      • highBits: number
      • Optional unsigned: boolean

      Returns Long

    Static fromBytes

    • fromBytes(bytes: number[], unsigned?: boolean, le?: boolean): Long
    • Creates a Long from its byte representation.

      -

      Parameters

      • bytes: number[]
      • Optional unsigned: boolean
      • Optional le: boolean

      Returns Long

    Static fromBytesBE

    • fromBytesBE(bytes: number[], unsigned?: boolean): Long
    • +

      Parameters

      • bytes: number[]
      • Optional unsigned: boolean
      • Optional le: boolean

      Returns Long

    Static fromBytesBE

    • fromBytesBE(bytes: number[], unsigned?: boolean): Long
    • Creates a Long from its big endian byte representation.

      -

      Parameters

      • bytes: number[]
      • Optional unsigned: boolean

      Returns Long

    Static fromBytesLE

    • fromBytesLE(bytes: number[], unsigned?: boolean): Long
    • +

      Parameters

      • bytes: number[]
      • Optional unsigned: boolean

      Returns Long

    Static fromBytesLE

    • fromBytesLE(bytes: number[], unsigned?: boolean): Long
    • Creates a Long from its little endian byte representation.

      -

      Parameters

      • bytes: number[]
      • Optional unsigned: boolean

      Returns Long

    Static fromInt

    • fromInt(value: number, unsigned?: boolean): Long
    • Parameters

      • value: number
      • Optional unsigned: boolean

      Returns Long

    Static fromNumber

    • fromNumber(value: number, unsigned?: boolean): Long
    • Parameters

      • value: number
      • Optional unsigned: boolean

      Returns Long

    Static fromString

    • fromString(str: string, unsigned?: number | boolean, radix?: number): Long
    • Parameters

      • str: string
      • Optional unsigned: number | boolean
      • Optional radix: number

      Returns Long

    Static fromValue

    • fromValue(val: string | number | Long | { high: number; low: number; unsigned: boolean }, unsigned?: boolean): Long
    • Parameters

      • val: string | number | Long | { high: number; low: number; unsigned: boolean }
      • Optional unsigned: boolean

      Returns Long

    Legend

    • Constructor
    • Property
    • Method
    • Static property
    • Static method

    Settings

    Theme

    Generated using TypeDoc

    \ No newline at end of file +

    Parameters

    • bytes: number[]
    • Optional unsigned: boolean

    Returns Long

Static fromInt

  • fromInt(value: number, unsigned?: boolean): Long
  • Parameters

    • value: number
    • Optional unsigned: boolean

    Returns Long

Static fromNumber

  • fromNumber(value: number, unsigned?: boolean): Long
  • Parameters

    • value: number
    • Optional unsigned: boolean

    Returns Long

Static fromString

  • fromString(str: string, unsigned?: number | boolean, radix?: number): Long
  • Parameters

    • str: string
    • Optional unsigned: number | boolean
    • Optional radix: number

    Returns Long

Static fromValue

  • fromValue(val: string | number | Long | { high: number; low: number; unsigned: boolean }, unsigned?: boolean): Long
  • Parameters

    • val: string | number | Long | { high: number; low: number; unsigned: boolean }
    • Optional unsigned: boolean

    Returns Long

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/index.html b/docs/index.html index a2266de..238cb96 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1 +1,30 @@ -long-ts
Options
All
  • Public
  • Public/Protected
  • All
Menu

long-ts

Generated using TypeDoc

\ No newline at end of file +long-ts
Options
All
  • Public
  • Public/Protected
  • All
Menu

long-ts

+ +

long-ts

+
+

An alternative to long.js with support for ESM, CJS, UMD and Modern Mode. It's written in TypeScript and thus houses it's own type declarations. The only notable differences between long-ts and long.js are the removal of Long.isLong() in favor of using instanceof. All aliased shorthand methods are also removed.

+ + +

Installation

+
+
npm install long-ts
+
+ + +

Usage

+
+
import { Long } from "long-ts";

const longVal = new Long(0xffffffff, 0x7fffffff);

console.log(longVal.toString()); +
+ + +

Documentation

+
+

https://hornta.github.io/long-ts/modules.html

+ + +

Developing

+
+

You are recommended to be using at least Node LTS during development.

+
# Builds the ESM, CJS, UMD, Modern Mode and TypeScript declaration files.
npm run build

# Executes the unit tests
npm run test

# Lint files
npm run lint

# Generates the /docs folder
npm run generateDocs +
+

Generated using TypeDoc

\ No newline at end of file diff --git a/package.json b/package.json index d5c1ad8..b3bb4e8 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,9 @@ "bugs": { "url": "https://github.com/hornta/long-ts/issues" }, + "files": [ + "dist" + ], "source": "./src/long.ts", "module": "./dist/long.js", "exports": "./dist/long.modern.js", @@ -25,10 +28,11 @@ "umd:main": "./dist/long.umd.js", "types": "./dist/long.d.ts", "scripts": { - "build": "microbundle", + "build": "microbundle && npm run generateDocs", "test": "jest", "lint": "eslint .", - "generateDocs": "typedoc --cleanOutputDir --gitRemote https://github.com/hornta/long-ts.git ./src/long.ts" + "generateDocs": "typedoc --cleanOutputDir ./src/long.ts", + "prepare": "npm run lint && npm run test && npm run build" }, "devDependencies": { "@types/jest": "^27.0.1",