@burstjs/util
Advanced tools
Comparing version 0.1.0-rc.2 to 0.1.0-rc.3
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
## 0.1.0-rc.3 | ||
- Timestamp conversion functions | ||
## 0.0.13 (2019-02-03) | ||
@@ -9,2 +12,2 @@ ### Added | ||
### Changed | ||
- Removed BurstUtils from `@burstjs/core`. | ||
- Removed BurstUtils from `@burstjs/core`. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const BN = require("bn.js"); | ||
const internal_1 = require("./internal"); | ||
@@ -59,4 +58,4 @@ const isBurstAddress_1 = require("./isBurstAddress"); | ||
} while (length > 0); | ||
return new BN(out.split('').reverse().join('')).toString(); | ||
return out.split('').reverse().join(''); | ||
}; | ||
//# sourceMappingURL=convertAddressToNumericId.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const GenesisBlockTime = Math.floor(new Date('2014-08-11T02:00:00.000Z').getTime() / 1000); | ||
const internal_1 = require("./internal"); | ||
exports.convertBurstTimeToEpochTime = (burstTimestamp) => { | ||
return (GenesisBlockTime + burstTimestamp) * 1000; | ||
return (internal_1.GenesisBlockTime + burstTimestamp) * 1000; | ||
}; | ||
//# sourceMappingURL=convertBurstTimeToEpochTime.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const BN = require("bn.js"); | ||
const internal_1 = require("./internal"); | ||
@@ -13,6 +12,5 @@ exports.convertNumericIdToAddress = (numericId) => { | ||
let pos = 0; | ||
const plainString = new BN(numericId).toString(); | ||
let length = plainString.length; | ||
let length = numericId.length; | ||
for (let i = 0; i < length; i++) { | ||
plainString10[i] = plainString.charCodeAt(i) - '0'.charCodeAt(0); | ||
plainString10[i] = numericId.charCodeAt(i) - '0'.charCodeAt(0); | ||
} | ||
@@ -19,0 +17,0 @@ let digit32 = 0, newLength = 0; |
@@ -5,2 +5,5 @@ export * from './constructBurstAddress'; | ||
export * from './convertNumericIdToAddress'; | ||
export * from './convertBurstTimeToEpochTime'; | ||
export * from './convertBurstTimeToDate'; | ||
export * from './convertDateToBurstTime'; | ||
export * from './convertAddressToNumericId'; | ||
@@ -7,0 +10,0 @@ export * from './isBurstAddress'; |
@@ -10,2 +10,5 @@ "use strict"; | ||
__export(require("./convertNumericIdToAddress")); | ||
__export(require("./convertBurstTimeToEpochTime")); | ||
__export(require("./convertBurstTimeToDate")); | ||
__export(require("./convertDateToBurstTime")); | ||
__export(require("./convertAddressToNumericId")); | ||
@@ -12,0 +15,0 @@ __export(require("./isBurstAddress")); |
@@ -0,1 +1,2 @@ | ||
export declare const GenesisBlockTime: number; | ||
export declare const initialCodeword: number[]; | ||
@@ -2,0 +3,0 @@ export declare const gexp: number[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GenesisBlockTime = Date.UTC(2014, 7, 11, 2, 0, 0, 0) / 1000; | ||
exports.initialCodeword = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
@@ -4,0 +5,0 @@ exports.gexp = [1, 2, 4, 8, 16, 5, 10, 20, 13, 26, 17, 7, 14, 28, 29, 31, 27, 19, 3, 6, 12, 24, 21, 15, 30, 25, 23, 11, 22, 9, 18, 1]; |
{ | ||
"name": "@burstjs/util", | ||
"version": "0.1.0-rc.2", | ||
"version": "0.1.0-rc.3", | ||
"description": "Useful utilities and tools for building Burstcoin applications", | ||
@@ -56,6 +56,3 @@ "keywords": [ | ||
}, | ||
"dependencies": { | ||
"bn.js": "^4.11.8" | ||
}, | ||
"gitHead": "8080c7a2fef903055d44793fe8ed5d1a864ff398" | ||
"gitHead": "049583d0dfbf99ba6328e2291d459e8f377c5625" | ||
} |
import {convertBurstTimeToEpochTime} from '../convertBurstTimeToEpochTime'; | ||
import {convertBurstTimeToDate} from '../convertBurstTimeToDate'; | ||
import {convertDateToBurstTime} from '../convertDateToBurstTime'; | ||
describe('convertBurstTimeToEpochTime', () => { | ||
describe('time Functions', () => { | ||
describe('convertBurstTimeToEpochTime', () => { | ||
it('should convertBurstTimeToEpochTime()', () => { | ||
const unixTime = convertBurstTimeToEpochTime(142850535); | ||
it('should convertBurstTimeToEpochTime()', () => { | ||
const unixTime = convertBurstTimeToEpochTime(142850535); | ||
const received = new Date(unixTime).toISOString(); | ||
const expected = '2019-02-19T10:42:15.000Z'; | ||
expect(received).toBe(expected); | ||
const received = new Date(unixTime).toISOString(); | ||
const expected = '2019-02-19T10:42:15.000Z'; | ||
expect(received).toBe(expected); | ||
}); | ||
it('should convertBurstTimeToEpochTime() to genesis Date', () => { | ||
const unixTime = convertBurstTimeToEpochTime(0); | ||
const received = new Date(unixTime).toISOString(); | ||
const expected = '2014-08-11T02:00:00.000Z'; | ||
expect(received).toBe(expected); | ||
}); | ||
it('should convertBurstTimeToEpochTime() to date before genesis block', () => { | ||
const unixTime = convertBurstTimeToEpochTime(-1); | ||
const received = new Date(unixTime).toISOString(); | ||
const expected = '2014-08-11T01:59:59.000Z'; | ||
expect(received).toBe(expected); | ||
}); | ||
}); | ||
it('should convertBurstTimeToEpochTime() to genesis Date', () => { | ||
const unixTime = convertBurstTimeToEpochTime(0); | ||
describe('convertBurstTimeToDate', () => { | ||
const received = new Date(unixTime).toISOString(); | ||
const expected = '2014-08-11T02:00:00.000Z'; | ||
expect(received).toBe(expected); | ||
it('should convertBurstTimeToDate()', () => { | ||
const received = convertBurstTimeToDate(142850535); | ||
const expected = new Date('2019-02-19T10:42:15.000Z'); | ||
expect(received).toEqual(expected); | ||
}); | ||
it('should convertBurstTimeToDate() to genesis Date', () => { | ||
const received = convertBurstTimeToDate(0); | ||
const expected = new Date('2014-08-11T02:00:00.000Z'); | ||
expect(received).toEqual(expected); | ||
}); | ||
}); | ||
it('should fail on convertBurstTimeToEpochTime() due to invalid numbers', () => { | ||
const unixTime = convertBurstTimeToEpochTime(-1); | ||
const received = new Date(unixTime).toISOString(); | ||
const expected = '2014-08-11T01:59:59.000Z'; | ||
expect(received).toBe(expected); | ||
describe('convertDateToBurstTime', () => { | ||
it('should convertDateToBurstTime()', () => { | ||
const date = new Date('2019-02-19T10:42:15.000Z'); | ||
const received = convertDateToBurstTime(date); | ||
const expected = 142850535; | ||
expect(received).toEqual(expected); | ||
}); | ||
it('should convertDateToBurstTime() with millies - round down', () => { | ||
const date = new Date('2019-02-19T10:42:15.250Z'); | ||
const received = convertDateToBurstTime(date); | ||
const expected = 142850535; | ||
expect(received).toEqual(expected); | ||
}); | ||
it('should convertDateToBurstTime() with millies - round up', () => { | ||
const date = new Date('2019-02-19T10:42:15.501Z'); | ||
const received = convertDateToBurstTime(date); | ||
const expected = 142850536; | ||
expect(received).toEqual(expected); | ||
}); | ||
it('should convertDateToBurstTime() of Genenis Date to Zero', () => { | ||
const date = new Date('2014-08-11T02:00:00.000Z'); | ||
const received = convertDateToBurstTime(date); | ||
const expected = 0; | ||
expect(received).toEqual(expected); | ||
}); | ||
}); | ||
}); |
@@ -9,3 +9,2 @@ /** @module util */ | ||
import * as BN from 'bn.js'; | ||
import { base32Length, cwmap, alphabet, initialCodeword } from './internal'; | ||
@@ -22,3 +21,2 @@ import { isValid } from './isBurstAddress'; | ||
if (address === undefined || | ||
@@ -30,3 +28,2 @@ address === null || | ||
// remove Burst prefix | ||
if (address.indexOf('BURST-') === 0) { | ||
@@ -90,3 +87,3 @@ address = address.substr(6); | ||
return new BN(out.split('').reverse().join('')).toString(); | ||
return out.split('').reverse().join(''); | ||
}; |
// tslint:disable:no-bitwise | ||
/** @module util */ | ||
import {GenesisBlockTime} from './internal'; | ||
/** | ||
@@ -8,8 +10,2 @@ * Original work Copyright (c) 2019 Burst Apps Team | ||
const GenesisBlockTime = Math.floor( | ||
new Date('2014-08-11T02:00:00.000Z').getTime() / 1000 | ||
); | ||
/** | ||
@@ -16,0 +12,0 @@ * Converts a Burst/Block Time (seconds since genesis block) into Unix Epoch Time (milliseconds since 01.01.1970) |
@@ -9,3 +9,2 @@ // tslint:disable:no-bitwise | ||
import * as BN from 'bn.js'; | ||
import { initialCodeword, base32Length, gmult, alphabet, cwmap } from './internal'; | ||
@@ -31,7 +30,6 @@ | ||
const plainString = new BN(numericId).toString(); | ||
let length = plainString.length; | ||
let length = numericId.length; | ||
for (let i = 0; i < length; i++) { | ||
plainString10[i] = plainString.charCodeAt(i) - '0'.charCodeAt(0); | ||
plainString10[i] = numericId.charCodeAt(i) - '0'.charCodeAt(0); | ||
} | ||
@@ -38,0 +36,0 @@ |
@@ -6,2 +6,5 @@ /** @module util */ | ||
export * from './convertNumericIdToAddress'; | ||
export * from './convertBurstTimeToEpochTime'; | ||
export * from './convertBurstTimeToDate'; | ||
export * from './convertDateToBurstTime'; | ||
export * from './convertAddressToNumericId'; | ||
@@ -13,5 +16,7 @@ export * from './isBurstAddress'; | ||
* A useful regex for matching burst addresses | ||
* | ||
*/ | ||
// TODO: I doubt that this should be in the lib. Very UI specific | ||
export const burstAddressPattern = { | ||
'_': {pattern: new RegExp('\[a-zA-Z0-9\]')} | ||
}; |
@@ -12,3 +12,3 @@ /** @ignore */ | ||
// Internal helper functions and structures | ||
export const GenesisBlockTime = Date.UTC(2014, 7, 11, 2, 0, 0, 0) / 1000; | ||
export const initialCodeword = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
@@ -34,1 +34,2 @@ export const gexp: number[] = [1, 2, 4, 8, 16, 5, 10, 20, 13, 26, 17, 7, 14, 28, 29, 31, 27, 19, 3, 6, 12, 24, 21, 15, 30, 25, 23, 11, 22, 9, 18, 1]; | ||
}; | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47479
0
56
824
- Removedbn.js@^4.11.8
- Removedbn.js@4.12.1(transitive)