steamutils 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/steamutils.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/axios.js +91 -0
- package/cheerio.js +71 -0
- package/example.js +12 -0
- package/index.js +4065 -0
- package/package.json +16 -0
- package/string.js +96 -0
- package/utils.js +100 -0
- package/xml2json.js +50 -0
package/package.json
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"name": "steamutils",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"dependencies": {
|
5
|
+
"axios": "^1.3.4",
|
6
|
+
"cheerio": "^1.0.0-rc.12",
|
7
|
+
"crypto-js": "^4.1.1",
|
8
|
+
"lodash": "^4.17.21",
|
9
|
+
"moment": "^2.29.4",
|
10
|
+
"node-bignumber": "^1.2.2",
|
11
|
+
"steamid": "^2.0.0",
|
12
|
+
"xml-js": "^1.6.11",
|
13
|
+
"xml2js": "^0.4.23"
|
14
|
+
},
|
15
|
+
"type": "module"
|
16
|
+
}
|
package/string.js
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
String.prototype.substringAfter = function (delimiter) {
|
2
|
+
const index = this.indexOf(delimiter)
|
3
|
+
if (index === -1) {
|
4
|
+
return this
|
5
|
+
}
|
6
|
+
return this.substring(index + delimiter.length)
|
7
|
+
}
|
8
|
+
|
9
|
+
String.prototype.substringAfterOrNull = function (delimiter) {
|
10
|
+
const index = this.indexOf(delimiter)
|
11
|
+
if (index === -1) {
|
12
|
+
return null
|
13
|
+
}
|
14
|
+
return this.substring(index + delimiter.length)
|
15
|
+
}
|
16
|
+
|
17
|
+
String.prototype.substringBefore = function (delimiter) {
|
18
|
+
const index = this.indexOf(delimiter)
|
19
|
+
if (index === -1) {
|
20
|
+
return this
|
21
|
+
}
|
22
|
+
return this.substring(0, index)
|
23
|
+
}
|
24
|
+
|
25
|
+
String.prototype.substringBeforeOrNull = function (delimiter) {
|
26
|
+
const index = this.indexOf(delimiter)
|
27
|
+
if (index === -1) {
|
28
|
+
return null
|
29
|
+
}
|
30
|
+
return this.substring(0, index)
|
31
|
+
}
|
32
|
+
|
33
|
+
String.prototype.substringBeforeLast = function (delimiter) {
|
34
|
+
const index = this.lastIndexOf(delimiter)
|
35
|
+
if (index === -1) {
|
36
|
+
return this
|
37
|
+
}
|
38
|
+
return this.substring(0, index)
|
39
|
+
}
|
40
|
+
|
41
|
+
String.prototype.substringBeforeLastOrNull = function (delimiter) {
|
42
|
+
const index = this.lastIndexOf(delimiter)
|
43
|
+
if (index === -1) {
|
44
|
+
return null
|
45
|
+
}
|
46
|
+
return this.substring(0, index)
|
47
|
+
}
|
48
|
+
|
49
|
+
String.prototype.substringAfterLast = function (delimiter) {
|
50
|
+
const index = this.lastIndexOf(delimiter)
|
51
|
+
if (index === -1) {
|
52
|
+
return this
|
53
|
+
}
|
54
|
+
return this.substring(index + delimiter.length)
|
55
|
+
}
|
56
|
+
|
57
|
+
String.prototype.substringAfterLastOrNull = function (delimiter) {
|
58
|
+
const index = this.lastIndexOf(delimiter)
|
59
|
+
if (index === -1) {
|
60
|
+
return null
|
61
|
+
}
|
62
|
+
return this.substring(index + delimiter.length)
|
63
|
+
}
|
64
|
+
|
65
|
+
String.prototype.removePrefix = function (prefix) {
|
66
|
+
if (!this.startsWith(prefix)) {
|
67
|
+
return this
|
68
|
+
}
|
69
|
+
return this.substring(prefix.length, this.length)
|
70
|
+
}
|
71
|
+
|
72
|
+
String.prototype.removeSuffix = function (suffix) {
|
73
|
+
if (!this.endsWith(suffix)) {
|
74
|
+
return this
|
75
|
+
}
|
76
|
+
return this.substring(0, this.length - suffix.length)
|
77
|
+
}
|
78
|
+
|
79
|
+
String.prototype.removeSurrounding = function (_fix) {
|
80
|
+
return this.removePrefix(_fix).removeSuffix(_fix)
|
81
|
+
}
|
82
|
+
|
83
|
+
String.prototype.substringBetween = function (prefix, suffix) {
|
84
|
+
return this.substringAfter(prefix).substringBefore(suffix)
|
85
|
+
}
|
86
|
+
|
87
|
+
String.prototype.substringBetweenOrNull = function (prefix, suffix) {
|
88
|
+
let text = this
|
89
|
+
|
90
|
+
text = text.substringAfterOrNull(prefix)
|
91
|
+
if (text === null) return null
|
92
|
+
|
93
|
+
text = text.substringBeforeOrNull(suffix)
|
94
|
+
if (text === null) return null
|
95
|
+
return text
|
96
|
+
}
|
package/utils.js
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
const isBrowser = typeof window !== 'undefined'
|
2
|
+
|
3
|
+
export const sleep = (ms) => {
|
4
|
+
return new Promise(resolve => {
|
5
|
+
setTimeout(resolve, ms)
|
6
|
+
})
|
7
|
+
}
|
8
|
+
|
9
|
+
|
10
|
+
/**
|
11
|
+
* const audioTrack = stream.getAudioTracks()[0]
|
12
|
+
* const videoStream = UserMedia.createBlankVideoTrack()
|
13
|
+
* videoStream.addTrack(audioTrack)
|
14
|
+
* stream = videoStream
|
15
|
+
* **/
|
16
|
+
export const createBlankVideoTrack = (opts = {}) => {
|
17
|
+
const {
|
18
|
+
width = 1920,
|
19
|
+
height = 1080
|
20
|
+
} = opts
|
21
|
+
|
22
|
+
const canvas = Object.assign(document.createElement('canvas'), {
|
23
|
+
width,
|
24
|
+
height,
|
25
|
+
})
|
26
|
+
|
27
|
+
canvas.getContext('2d').fillRect(0, 0, width, height)
|
28
|
+
|
29
|
+
return canvas.captureStream()
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
const minDate = new Date(0),
|
34
|
+
maxDate = new Date(parseInt('ffffffff', 16) * 1000)
|
35
|
+
|
36
|
+
export function objectIdFromDate(date) {
|
37
|
+
if(date < minDate || date > maxDate) {
|
38
|
+
return 'Error: date must be between ' + minDate.getFullYear() + ' and ' + maxDate.getFullYear()
|
39
|
+
}
|
40
|
+
var pad = '00000000'
|
41
|
+
var hexSeconds = Math.floor(date.getTime() / 1000).toString(16)
|
42
|
+
return pad.substring(0, pad.length - hexSeconds.length) + hexSeconds + '0000000000000000'
|
43
|
+
}
|
44
|
+
|
45
|
+
export function dateFromObjectId(objectId) {
|
46
|
+
return new Date(parseInt(objectId.substring(0, 8), 16) * 1000)
|
47
|
+
}
|
48
|
+
|
49
|
+
export function console_log(...args) {
|
50
|
+
const params = []
|
51
|
+
params.push(new Date().toUTCString())
|
52
|
+
const errorStack = (new Error()).stack
|
53
|
+
const fnName = errorStack.split('\n').map(e => e?.trim()).filter(e => e.startsWith('at') && !e.startsWith('at console_log') && !e.startsWith('at processTicksAndRejections'))[0].substr(3)
|
54
|
+
params.push(fnName)
|
55
|
+
console.log(params.filter(Boolean).map(p => `[${p.trim()}]`).join(' '), ...args)
|
56
|
+
}
|
57
|
+
|
58
|
+
export function removeSpaceKeys(object) {//mutate object
|
59
|
+
if(!object || Array.isArray(object)) {
|
60
|
+
return object
|
61
|
+
}
|
62
|
+
|
63
|
+
Object.entries(object).forEach(([key, value]) => {
|
64
|
+
const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, '_')
|
65
|
+
if(newKey !== key) {
|
66
|
+
delete object[key]
|
67
|
+
object[newKey] = value
|
68
|
+
}
|
69
|
+
})
|
70
|
+
return object
|
71
|
+
}
|
72
|
+
|
73
|
+
export function getCleanObject(object) {//like removeSpaceKeys but not mutate object
|
74
|
+
if(!object || Array.isArray(object)) {
|
75
|
+
return object
|
76
|
+
}
|
77
|
+
|
78
|
+
const newObject = {}
|
79
|
+
Object.entries(object).forEach(([key, value]) => {
|
80
|
+
const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, '_')
|
81
|
+
newObject[newKey] = value
|
82
|
+
})
|
83
|
+
return newObject
|
84
|
+
}
|
85
|
+
|
86
|
+
export function JSON_parse(data) {
|
87
|
+
try {
|
88
|
+
return JSON.parse(data)
|
89
|
+
} catch (e) {
|
90
|
+
return null
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
export function JSON_stringify(data) {
|
95
|
+
try {
|
96
|
+
return JSON.stringify(data)
|
97
|
+
} catch (e) {
|
98
|
+
return null
|
99
|
+
}
|
100
|
+
}
|
package/xml2json.js
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
import fs from 'fs'
|
2
|
+
import {xml2js} from 'xml-js'
|
3
|
+
|
4
|
+
const xml2jsOption = {
|
5
|
+
compact: true,
|
6
|
+
trim: true,
|
7
|
+
nativeType: false,
|
8
|
+
spaces: 4
|
9
|
+
}
|
10
|
+
|
11
|
+
function getObjectValueString(obj) {
|
12
|
+
let key
|
13
|
+
if(typeof obj === 'object' && Object.keys(obj).length === 1 && typeof (key = Object.keys(obj)[0]) === 'string') {
|
14
|
+
return obj[key]
|
15
|
+
}
|
16
|
+
return obj
|
17
|
+
}
|
18
|
+
|
19
|
+
function formatObject(obj) {
|
20
|
+
try {
|
21
|
+
for (let key in obj) {
|
22
|
+
const _value = getObjectValueString(obj[key])
|
23
|
+
if(typeof _value === 'string') {
|
24
|
+
obj[key] = _value
|
25
|
+
}
|
26
|
+
else {
|
27
|
+
formatObject(obj[key])
|
28
|
+
}
|
29
|
+
}
|
30
|
+
} catch (e) {
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
export function getJSObjectFronXML(xml) {
|
35
|
+
let result
|
36
|
+
try {
|
37
|
+
result = xml2js(xml, xml2jsOption)
|
38
|
+
} catch (e) {
|
39
|
+
try {
|
40
|
+
fs.writeFileSync(`getJSObjectFronXMLError_${new Date().getTime()}.txt`, xml)
|
41
|
+
} catch (e) {
|
42
|
+
}
|
43
|
+
}
|
44
|
+
if(!result) {
|
45
|
+
return result
|
46
|
+
}
|
47
|
+
delete result._declaration
|
48
|
+
formatObject(result)
|
49
|
+
return result
|
50
|
+
}
|