@0xsequence/utils
Advanced tools
Comparing version 0.18.0 to 0.19.0
# @0xsequence/utils | ||
## 0.19.0 | ||
### Minor Changes | ||
- - provider, improve dapp / wallet transport io | ||
## 0.18.0 | ||
@@ -4,0 +10,0 @@ |
@@ -5,5 +5,27 @@ 'use strict'; | ||
var jsBase64 = require('js-base64'); | ||
var ethers = require('ethers'); | ||
var properties = require('@ethersproject/properties'); | ||
const base64Encode = val => { | ||
return jsBase64.Base64.encode(val, true); | ||
}; | ||
const base64EncodeObject = obj => { | ||
return jsBase64.Base64.encode(JSON.stringify(obj), true); | ||
}; | ||
const base64Decode = encodedString => { | ||
if (encodedString === null || encodedString === undefined) { | ||
return undefined; | ||
} | ||
return jsBase64.Base64.decode(encodedString); | ||
}; | ||
const base64DecodeObject = encodedObject => { | ||
if (encodedObject === null || encodedObject === undefined) { | ||
return undefined; | ||
} | ||
return JSON.parse(jsBase64.Base64.decode(encodedObject)); | ||
}; | ||
const encodeMessageDigest = message => { | ||
@@ -33,2 +55,13 @@ if (typeof message === 'string') { | ||
const jwtDecodeClaims = jwt => { | ||
const parts = jwt.split('.'); | ||
if (parts.length !== 3) { | ||
throw new Error('invalid jwt'); | ||
} | ||
const claims = JSON.parse(jsBase64.Base64.decode(parts[1])); | ||
return claims; | ||
}; | ||
function _extends() { | ||
@@ -157,2 +190,19 @@ _extends = Object.assign || function (target) { | ||
function queryStringFromObject(name, obj) { | ||
const k = encodeURIComponent(name); | ||
const v = encodeURIComponent(JSON.stringify(obj)); | ||
return `${k}=${v}`; | ||
} | ||
function queryStringToObject(qs) { | ||
const p = qs.split('&'); | ||
const o = {}; | ||
for (const v of p) { | ||
const z = v.split('='); | ||
o[decodeURIComponent(z[0])] = JSON.parse(decodeURIComponent(z[1])); | ||
} | ||
return o; | ||
} | ||
// sanitizeNumberString accepts a number string and returns back a clean number string. | ||
@@ -166,3 +216,21 @@ // For example, input '1234.5678' will return '1234.5678' but '12javascript:{}etc' will return '12' | ||
const v = numString.match(/[\d.]+/); | ||
return v && v.length > 0 ? v[0] : ''; | ||
return v && v.length > 0 ? v[0].trim() : ''; | ||
}; // sanitizeAlphanumeric accepts any string and returns alphanumeric contents only | ||
const sanitizeAlphanumeric = alphanum => { | ||
if (!alphanum || typeof alphanum !== 'string') { | ||
return ''; | ||
} | ||
const v = alphanum.match(/[\w\s\d]+/); | ||
return v && v.length > 0 ? v[0].trim() : ''; | ||
}; // sanitizeHost accepts any string and returns valid host string | ||
const sanitizeHost = host => { | ||
if (!host || typeof host !== 'string') { | ||
return ''; | ||
} | ||
const v = host.match(/[\w\d.\-:\/]+/); | ||
return v && v.length > 0 ? v[0].trim() : ''; | ||
}; | ||
@@ -231,2 +299,6 @@ | ||
exports.Logger = Logger; | ||
exports.base64Decode = base64Decode; | ||
exports.base64DecodeObject = base64DecodeObject; | ||
exports.base64Encode = base64Encode; | ||
exports.base64EncodeObject = base64EncodeObject; | ||
exports.configureLogger = configureLogger; | ||
@@ -239,5 +311,10 @@ exports.encodeMessageDigest = encodeMessageDigest; | ||
exports.isNode = isNode; | ||
exports.jwtDecodeClaims = jwtDecodeClaims; | ||
exports.logger = logger; | ||
exports.packMessageData = packMessageData; | ||
exports.promisify = promisify; | ||
exports.queryStringFromObject = queryStringFromObject; | ||
exports.queryStringToObject = queryStringToObject; | ||
exports.sanitizeAlphanumeric = sanitizeAlphanumeric; | ||
exports.sanitizeHost = sanitizeHost; | ||
exports.sanitizeNumberString = sanitizeNumberString; | ||
@@ -244,0 +321,0 @@ exports.sleep = sleep; |
@@ -5,5 +5,27 @@ 'use strict'; | ||
var jsBase64 = require('js-base64'); | ||
var ethers = require('ethers'); | ||
var properties = require('@ethersproject/properties'); | ||
const base64Encode = val => { | ||
return jsBase64.Base64.encode(val, true); | ||
}; | ||
const base64EncodeObject = obj => { | ||
return jsBase64.Base64.encode(JSON.stringify(obj), true); | ||
}; | ||
const base64Decode = encodedString => { | ||
if (encodedString === null || encodedString === undefined) { | ||
return undefined; | ||
} | ||
return jsBase64.Base64.decode(encodedString); | ||
}; | ||
const base64DecodeObject = encodedObject => { | ||
if (encodedObject === null || encodedObject === undefined) { | ||
return undefined; | ||
} | ||
return JSON.parse(jsBase64.Base64.decode(encodedObject)); | ||
}; | ||
const encodeMessageDigest = message => { | ||
@@ -33,2 +55,13 @@ if (typeof message === 'string') { | ||
const jwtDecodeClaims = jwt => { | ||
const parts = jwt.split('.'); | ||
if (parts.length !== 3) { | ||
throw new Error('invalid jwt'); | ||
} | ||
const claims = JSON.parse(jsBase64.Base64.decode(parts[1])); | ||
return claims; | ||
}; | ||
function _extends() { | ||
@@ -157,2 +190,19 @@ _extends = Object.assign || function (target) { | ||
function queryStringFromObject(name, obj) { | ||
const k = encodeURIComponent(name); | ||
const v = encodeURIComponent(JSON.stringify(obj)); | ||
return `${k}=${v}`; | ||
} | ||
function queryStringToObject(qs) { | ||
const p = qs.split('&'); | ||
const o = {}; | ||
for (const v of p) { | ||
const z = v.split('='); | ||
o[decodeURIComponent(z[0])] = JSON.parse(decodeURIComponent(z[1])); | ||
} | ||
return o; | ||
} | ||
// sanitizeNumberString accepts a number string and returns back a clean number string. | ||
@@ -166,3 +216,21 @@ // For example, input '1234.5678' will return '1234.5678' but '12javascript:{}etc' will return '12' | ||
const v = numString.match(/[\d.]+/); | ||
return v && v.length > 0 ? v[0] : ''; | ||
return v && v.length > 0 ? v[0].trim() : ''; | ||
}; // sanitizeAlphanumeric accepts any string and returns alphanumeric contents only | ||
const sanitizeAlphanumeric = alphanum => { | ||
if (!alphanum || typeof alphanum !== 'string') { | ||
return ''; | ||
} | ||
const v = alphanum.match(/[\w\s\d]+/); | ||
return v && v.length > 0 ? v[0].trim() : ''; | ||
}; // sanitizeHost accepts any string and returns valid host string | ||
const sanitizeHost = host => { | ||
if (!host || typeof host !== 'string') { | ||
return ''; | ||
} | ||
const v = host.match(/[\w\d.\-:\/]+/); | ||
return v && v.length > 0 ? v[0].trim() : ''; | ||
}; | ||
@@ -231,2 +299,6 @@ | ||
exports.Logger = Logger; | ||
exports.base64Decode = base64Decode; | ||
exports.base64DecodeObject = base64DecodeObject; | ||
exports.base64Encode = base64Encode; | ||
exports.base64EncodeObject = base64EncodeObject; | ||
exports.configureLogger = configureLogger; | ||
@@ -239,5 +311,10 @@ exports.encodeMessageDigest = encodeMessageDigest; | ||
exports.isNode = isNode; | ||
exports.jwtDecodeClaims = jwtDecodeClaims; | ||
exports.logger = logger; | ||
exports.packMessageData = packMessageData; | ||
exports.promisify = promisify; | ||
exports.queryStringFromObject = queryStringFromObject; | ||
exports.queryStringToObject = queryStringToObject; | ||
exports.sanitizeAlphanumeric = sanitizeAlphanumeric; | ||
exports.sanitizeHost = sanitizeHost; | ||
exports.sanitizeNumberString = sanitizeNumberString; | ||
@@ -244,0 +321,0 @@ exports.sleep = sleep; |
@@ -0,4 +1,26 @@ | ||
import { Base64 } from 'js-base64'; | ||
import { ethers } from 'ethers'; | ||
export { checkProperties, deepCopy, defineReadOnly, getStatic, resolveProperties, shallowCopy } from '@ethersproject/properties'; | ||
const base64Encode = val => { | ||
return Base64.encode(val, true); | ||
}; | ||
const base64EncodeObject = obj => { | ||
return Base64.encode(JSON.stringify(obj), true); | ||
}; | ||
const base64Decode = encodedString => { | ||
if (encodedString === null || encodedString === undefined) { | ||
return undefined; | ||
} | ||
return Base64.decode(encodedString); | ||
}; | ||
const base64DecodeObject = encodedObject => { | ||
if (encodedObject === null || encodedObject === undefined) { | ||
return undefined; | ||
} | ||
return JSON.parse(Base64.decode(encodedObject)); | ||
}; | ||
const encodeMessageDigest = message => { | ||
@@ -28,2 +50,13 @@ if (typeof message === 'string') { | ||
const jwtDecodeClaims = jwt => { | ||
const parts = jwt.split('.'); | ||
if (parts.length !== 3) { | ||
throw new Error('invalid jwt'); | ||
} | ||
const claims = JSON.parse(Base64.decode(parts[1])); | ||
return claims; | ||
}; | ||
function _extends() { | ||
@@ -152,2 +185,19 @@ _extends = Object.assign || function (target) { | ||
function queryStringFromObject(name, obj) { | ||
const k = encodeURIComponent(name); | ||
const v = encodeURIComponent(JSON.stringify(obj)); | ||
return `${k}=${v}`; | ||
} | ||
function queryStringToObject(qs) { | ||
const p = qs.split('&'); | ||
const o = {}; | ||
for (const v of p) { | ||
const z = v.split('='); | ||
o[decodeURIComponent(z[0])] = JSON.parse(decodeURIComponent(z[1])); | ||
} | ||
return o; | ||
} | ||
// sanitizeNumberString accepts a number string and returns back a clean number string. | ||
@@ -161,3 +211,21 @@ // For example, input '1234.5678' will return '1234.5678' but '12javascript:{}etc' will return '12' | ||
const v = numString.match(/[\d.]+/); | ||
return v && v.length > 0 ? v[0] : ''; | ||
return v && v.length > 0 ? v[0].trim() : ''; | ||
}; // sanitizeAlphanumeric accepts any string and returns alphanumeric contents only | ||
const sanitizeAlphanumeric = alphanum => { | ||
if (!alphanum || typeof alphanum !== 'string') { | ||
return ''; | ||
} | ||
const v = alphanum.match(/[\w\s\d]+/); | ||
return v && v.length > 0 ? v[0].trim() : ''; | ||
}; // sanitizeHost accepts any string and returns valid host string | ||
const sanitizeHost = host => { | ||
if (!host || typeof host !== 'string') { | ||
return ''; | ||
} | ||
const v = host.match(/[\w\d.\-:\/]+/); | ||
return v && v.length > 0 ? v[0].trim() : ''; | ||
}; | ||
@@ -189,2 +257,2 @@ | ||
export { Logger, configureLogger, encodeMessageDigest, encodeTypedDataDigest, encodeTypedDataHash, getRandomInt, isBrowser, isNode, logger, packMessageData, promisify, sanitizeNumberString, sleep, subDigestOf, urlClean }; | ||
export { Logger, base64Decode, base64DecodeObject, base64Encode, base64EncodeObject, configureLogger, encodeMessageDigest, encodeTypedDataDigest, encodeTypedDataHash, getRandomInt, isBrowser, isNode, jwtDecodeClaims, logger, packMessageData, promisify, queryStringFromObject, queryStringToObject, sanitizeAlphanumeric, sanitizeHost, sanitizeNumberString, sleep, subDigestOf, urlClean }; |
@@ -0,6 +1,9 @@ | ||
export * from './base64'; | ||
export * from './digest'; | ||
export * from './is-node-or-browser'; | ||
export * from './jwt-decode'; | ||
export * from './logger'; | ||
export * from './promisify'; | ||
export * from './rand'; | ||
export * from './query-string'; | ||
export * from './sanitize'; | ||
@@ -7,0 +10,0 @@ export * from './sleep'; |
export declare const sanitizeNumberString: (numString: string) => string; | ||
export declare const sanitizeAlphanumeric: (alphanum: string) => string; | ||
export declare const sanitizeHost: (host: string) => string; |
{ | ||
"name": "@0xsequence/utils", | ||
"version": "0.18.0", | ||
"version": "0.19.0", | ||
"description": "utils sub-package for Sequence", | ||
@@ -12,3 +12,4 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/utils", | ||
"scripts": { | ||
"test": "echo", | ||
"test": "yarn test:file tests/**/*.spec.ts", | ||
"test:file": "TS_NODE_PROJECT=../../tsconfig.test.json mocha -r ts-node/register --timeout 30000", | ||
"typecheck": "tsc --noEmit" | ||
@@ -19,3 +20,4 @@ }, | ||
"@ethersproject/properties": "^5.0.9", | ||
"ethers": "^5.0.32" | ||
"ethers": "^5.0.32", | ||
"js-base64": "^3.6.0" | ||
}, | ||
@@ -22,0 +24,0 @@ "peerDependencies": {}, |
@@ -0,6 +1,9 @@ | ||
export * from './base64' | ||
export * from './digest' | ||
export * from './is-node-or-browser' | ||
export * from './jwt-decode' | ||
export * from './logger' | ||
export * from './promisify' | ||
export * from './rand' | ||
export * from './query-string' | ||
export * from './sanitize' | ||
@@ -7,0 +10,0 @@ export * from './sleep' |
@@ -9,3 +9,21 @@ | ||
const v = numString.match(/[\d.]+/) | ||
return v && v.length > 0 ? v[0] : '' | ||
return v && v.length > 0 ? v[0].trim() : '' | ||
} | ||
// sanitizeAlphanumeric accepts any string and returns alphanumeric contents only | ||
export const sanitizeAlphanumeric = (alphanum: string): string => { | ||
if (!alphanum || typeof(alphanum) !== 'string') { | ||
return '' | ||
} | ||
const v = alphanum.match(/[\w\s\d]+/) | ||
return v && v.length > 0 ? v[0].trim() : '' | ||
} | ||
// sanitizeHost accepts any string and returns valid host string | ||
export const sanitizeHost = (host: string): string => { | ||
if (!host || typeof(host) !== 'string') { | ||
return '' | ||
} | ||
const v = host.match(/[\w\d.\-:\/]+/) | ||
return v && v.length > 0 ? v[0].trim() : '' | ||
} |
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
40925
36
1069
4
+ Addedjs-base64@^3.6.0
+ Addedjs-base64@3.7.7(transitive)