node-steam-converter 0.1.4 → 1.2.2

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/README.md CHANGED
@@ -11,28 +11,37 @@ npm install node-steam-converter
11
11
  # Examples
12
12
 
13
13
  ```
14
- var convertTo = require('node-steam-converter');
15
-
16
- convertTo.steam64ID('76561197982486517', function(err, steam64ID) {
17
- //76561197982486517
18
- console.log(err, steam64ID);
19
- });
14
+ import convertTo from node-steam-converter;
15
+
16
+ try {
17
+
18
+ const converted = convertTo.eachConversion('76561197982486517');
19
+ // -> {
20
+ '3ID': '[U:1:22220789]',
21
+ '32ID': 'STEAM_0:1:11110394',
22
+ '64ID':'76561197982486517'
23
+ }
24
+
25
+ const steam64ID = convertTo.steam64ID('76561197982486517');
26
+ // -> 76561197982486517
27
+ const steam3ID = convertTo.steam3ID('STEAM_0:1:11110394');
28
+ // -> [U:1:22220789]
29
+ const steam32ID = convertTo.steam32ID('76561197982486517');
30
+ // -> STEAM_0:1:11110394
31
+ } catch (err) {
32
+ console.log(err);
33
+ }
34
+ ```
20
35
 
21
- convertTo.steam3ID('STEAM_0:1:11110394', function(err, steam3ID) {
22
- //[U:1:22220789]
23
- console.log(err, steam3ID);
24
- });
25
36
 
26
- convertTo.steam32ID('76561197982486517', function(err, steam32ID) {
27
- //STEAM_0:1:11110394
28
- console.log(err, steam32ID);
29
- });
30
37
 
31
- ```
38
+ ---
32
39
 
40
+ # Contribute
33
41
 
42
+ Pull requests are welcomed and encouraged!
34
43
 
35
- ---
44
+ --
36
45
 
37
- If you have any questions, suggestions, or bugs reports please feel free to contact me at alexbarkell@gmail.com
46
+ If you have any questions, suggestions, or bugs reports please feel free to open an issue.
38
47
 
package/index.mjs ADDED
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+ function determineIncomingFormat ( steamID ) {
3
+ try {
4
+ if ( steamID.length == 17 ) {
5
+ return 'steam64ID';
6
+ } else if ( steamID.substring(0, 3) == '[U:' ) {
7
+ return 'steam3ID';
8
+ } else if ( steamID.substring(0, 8) == 'STEAM_0:') {
9
+ return 'steam32ID';
10
+ } else {
11
+ new Error('invalid input format')
12
+ }
13
+ } catch (err) {
14
+ new Error('invalid input format')
15
+ }
16
+
17
+ };
18
+ export default {
19
+ eachConversion (steamID) {
20
+ determineIncomingFormat(steamID);
21
+ return {
22
+ '3ID': this.steam3ID(steamID),
23
+ '32ID': this.steam32ID(steamID),
24
+ '64ID': this.steam64ID(steamID)
25
+ }
26
+ },
27
+ steam64ID( steamID ) {
28
+ const IDFormat = determineIncomingFormat(steamID);
29
+ var steam64ID = '';
30
+
31
+ if ( IDFormat == 'steam3ID' ) {
32
+
33
+ steamID = steamID.replace('[U:1:', '');
34
+ steamID.substring(0, steamID.length - 1);
35
+
36
+
37
+ steam64ID = '765' + (parseInt(steamID) + 61197960265728);
38
+
39
+ return steam64ID;
40
+
41
+ } else if (IDFormat === 'steam32ID') {
42
+ const parts = steamID.split(':');
43
+ if (parts.length !== 3 || parts[0] !== 'STEAM_0') {
44
+ throw new Error('Invalid SteamID32 format');
45
+ }
46
+
47
+ const y = Number(parts[1]);
48
+ const z = Number(parts[2]);
49
+
50
+ if (!Number.isInteger(y) || y < 0 || y > 1 || !Number.isInteger(z) || z < 0) {
51
+ throw new Error('Invalid SteamID32 values');
52
+ }
53
+
54
+ const accountId = BigInt(z) * 2n + BigInt(y);
55
+ const steam64 = 76561197960265728n + accountId;
56
+
57
+ return steam64.toString();
58
+ } else if ( IDFormat == 'steam64ID' ) {
59
+
60
+ return steamID;
61
+ }
62
+ },
63
+ steam32ID( steamID ) {
64
+ const IDFormat = determineIncomingFormat(steamID);
65
+
66
+ var steam32ID = '';
67
+ var middleNumber = '';
68
+
69
+ if (IDFormat === 'steam64ID') {
70
+ const steam64 = BigInt(steamID);
71
+ const universeBase = 76561197960265728n;
72
+
73
+ const accountId = steam64 - universeBase;
74
+ const middleDigit = Number(accountId % 2n); // 0 or 1
75
+ const authServer = Number(accountId / 2n); // integer division
76
+
77
+ return `STEAM_0:${middleDigit}:${authServer}`;
78
+
79
+
80
+ } else if ( IDFormat == 'steam3ID' ) {
81
+ const steam64ID = this.steam64ID( steamID);
82
+ const steam32ID = this.steam32ID( steam64ID);
83
+ return steam32ID;
84
+ } else if ( IDFormat == 'steam32ID' ) {
85
+ return steamID;
86
+ }
87
+ },
88
+ steam3ID( steamID ) {
89
+ const IDFormat = determineIncomingFormat(steamID);
90
+ console.log('watf', steamID, IDFormat)
91
+ if ( IDFormat == 'steam64ID' ) {
92
+ var steam3ID = '';
93
+
94
+ if ( steamID.toString().length == 17 ) {
95
+
96
+ steam3ID = steamID.substring( steamID, 3 ) - 61197960265728;
97
+ steam3ID = '[U:1:' + steam3ID.toString() + ']';
98
+ return steam3ID;
99
+ }
100
+ } else if ( IDFormat == 'steam32ID' ) {
101
+ const steam64ID = this.steam64ID(steamID);
102
+ const steam3ID = this.steam3ID(steam64ID);
103
+ return steam3ID;
104
+ } else if ( IDFormat == 'steam3ID') {
105
+ return steamID;
106
+ }
107
+ }
108
+ }
package/package.json CHANGED
@@ -1,24 +1,20 @@
1
1
  {
2
2
  "name": "node-steam-converter",
3
- "version": "0.1.4",
3
+ "version": "1.2.2",
4
4
  "private": false,
5
5
  "description": "convert any steamIDs to any other steamIDs",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/bluejellybean/node-steam-converter.git"
9
9
  },
10
- "devDependencies": {
11
- "grunt": "~0.4.5",
12
- "grunt-contrib-watch": "~0.6.1",
13
- "grunt-develop": "~0.4.0",
14
- "grunt-mocha-test": "^0.12.7",
15
- "load-grunt-tasks": "^3.2.0",
16
- "mocha": "^2.3.2",
17
- "time-grunt": "^1.2.1"
10
+ "type": "module",
11
+ "scripts": {
12
+ "test": "node --test"
18
13
  },
19
- "dependencies": {
20
- "bignumber.js": "^2.0.7"
14
+ "devDependencies": {
15
+ "mocha": "^11.7.5"
21
16
  },
22
- "license" : "GPL-2.0",
17
+ "dependencies": {},
18
+ "license": "GPL-2.0",
23
19
  "author": "bluejellybean"
24
20
  }
@@ -0,0 +1,106 @@
1
+ import { strict as assert } from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+ import convertTo from '../index.mjs';
4
+
5
+ describe('node-steam-conversions', function(){
6
+ describe('eachConversion', function() {
7
+ it('should should return each conversion when given the 64ID', function(){
8
+ let conversions = convertTo.eachConversion('76561197982486517');
9
+ assert.deepEqual(conversions,
10
+ {
11
+ '3ID': '[U:1:22220789]',
12
+ '32ID': 'STEAM_0:1:11110394',
13
+ '64ID':'76561197982486517'
14
+ }
15
+ );
16
+ }),
17
+ it('should should return each conversion when given the 32ID', function(){
18
+ let conversions = convertTo.eachConversion('STEAM_0:1:11110394');
19
+ assert.deepEqual(conversions,
20
+ {
21
+ '3ID': '[U:1:22220789]',
22
+ '32ID': 'STEAM_0:1:11110394',
23
+ '64ID':'76561197982486517'
24
+ }
25
+ );
26
+ }),
27
+ it('should should return each conversion when given the 3ID', function(){
28
+ let conversions = convertTo.eachConversion('[U:1:22220789]');
29
+ assert.deepEqual(conversions,
30
+ {
31
+ '3ID': '[U:1:22220789]',
32
+ '32ID': 'STEAM_0:1:11110394',
33
+ '64ID':'76561197982486517'
34
+ }
35
+ );
36
+ }),
37
+ it('should return error when provided with invalid input', function(){
38
+ try {
39
+ let conversions = convertTo.eachConversion('');
40
+ } catch (err) {
41
+ assert.equal(err, new Error('invalid input format'));
42
+ }
43
+ })
44
+ })
45
+
46
+ describe('steam32ID', function(){
47
+ it('should should return the 32ID when given the 64ID', function(){
48
+ const steam32ID = convertTo.steam32ID( '76561197982486517');
49
+ assert.equal( 'STEAM_0:1:11110394', steam32ID );
50
+ })
51
+
52
+ it('should should return the 32ID when given the 3ID', function(){
53
+ const steam32ID = convertTo.steam32ID( '[U:1:22220789]');
54
+ assert.equal( 'STEAM_0:1:11110394', steam32ID );
55
+ })
56
+
57
+ it('should should return the 32ID when given the 32ID', function(){
58
+ const steam32ID = convertTo.steam32ID( 'STEAM_0:1:11110394');
59
+ assert.equal( 'STEAM_0:1:11110394', steam32ID );
60
+ })
61
+ })
62
+
63
+ describe('steam64ID', function(){
64
+ it('should should return the 64ID when given the 3ID', function(){
65
+ const steam64ID = convertTo.steam64ID( '[U:1:22220789]');
66
+ assert.equal('76561197982486517', steam64ID);
67
+
68
+ }),
69
+ it('should should return the 64ID when given the 32ID', function(){
70
+ const steam64ID = convertTo.steam64ID( 'STEAM_0:1:11110394');
71
+ assert.equal('76561197982486517', steam64ID);
72
+ })
73
+ }),
74
+
75
+ it('should should return the 64ID when given the 64ID', function(){
76
+ const steam64ID = convertTo.steam64ID( '76561197982486517');
77
+ assert.equal('76561197982486517', steam64ID);
78
+ })
79
+
80
+ describe('steam3ID', function(){
81
+ it('should return the 3ID when given the 64ID', function () {
82
+ const steam3ID = convertTo.steam3ID( '76561197982486517');
83
+ assert.equal('[U:1:22220789]', steam3ID);
84
+ })
85
+
86
+ it('should return the 3ID when given the 32ID', function () {
87
+ const steam3ID = convertTo.steam3ID('STEAM_0:1:11110394');
88
+ assert.equal('[U:1:22220789]', steam3ID);
89
+ })
90
+
91
+ it('should return the 3ID when given the 3ID', function () {
92
+ const steam3ID = convertTo.steam3ID( '[U:1:22220789]');
93
+ assert.equal('[U:1:22220789]', steam3ID);
94
+ })
95
+ })
96
+
97
+ describe('error handling', function() {
98
+ it('should return error when provided with invalid input', function() {
99
+ try {
100
+ convertTo.steam64ID('abc');
101
+ } catch(err) {
102
+ assert.equal(err, new Error('invalid input format'));
103
+ }
104
+ })
105
+ })
106
+ });
package/.npmignore DELETED
@@ -1 +0,0 @@
1
- node_modules/
package/Gruntfile.js DELETED
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = function (grunt) {
4
- // show elapsed time at the end
5
- require('time-grunt')(grunt);
6
- // load all grunt tasks
7
- require('load-grunt-tasks')(grunt);
8
- grunt.loadNpmTasks('grunt-mocha-test');
9
- var reloadPort = 35732, files;
10
- grunt.initConfig({
11
- pkg: grunt.file.readJSON('package.json'),
12
- develop: {
13
- server: {
14
- file: 'index.js'
15
- }
16
- },
17
- mochaTest: {
18
- test: {
19
- options: {
20
- reporter: 'dot',
21
- quiet: false, // Optionally suppress output to standard out (defaults to false)
22
- clearRequireCache: true // Optionally clear the require cache before running tests (defaults to false)
23
- },
24
- src: ['tests/*.js']
25
- }
26
- },
27
- watch: {
28
- options: {
29
- nospawn: true,
30
- livereload: reloadPort
31
- },
32
- js: {
33
- files: [
34
- '/',
35
- 'tests/*.js',
36
- 'index.js'
37
- ],
38
- tasks: ['develop', 'mochaTest']
39
- }
40
- }
41
- });
42
-
43
- grunt.config.requires('watch.js.files');
44
- files = grunt.config('watch.js.files');
45
- files = grunt.file.expand(files);
46
-
47
- grunt.registerTask('default', [
48
- 'mochaTest',
49
- 'develop',
50
- 'watch'
51
- ]);
52
- };
53
-
54
-
package/index.js DELETED
@@ -1,123 +0,0 @@
1
- 'use strict';
2
-
3
- var exports = module.exports = {};
4
-
5
- var bignumber = require('bignumber.js');
6
-
7
-
8
- var determineIncomingFormat = function (steamID, callback) {
9
-
10
- if ( steamID.length == 17 ) {
11
- callback( null, 'steam64ID' );
12
- } else if ( steamID.substring(0, 3) == '[U:' ) {
13
- callback( null, 'steam3ID' );
14
- } else if ( steamID.substring(0, 8) == 'STEAM_0:') {
15
- callback( null, 'steam32ID' );
16
- }
17
-
18
- };
19
-
20
- exports.steam64ID = function( steamID, callback ) {
21
- determineIncomingFormat(steamID, function(err, IDFormat) {
22
- var steam64ID = '';
23
-
24
- if ( IDFormat == 'steam3ID' ) {
25
-
26
- steamID = steamID.replace('[U:1:', '');
27
- steamID.substring(0, steamID.length - 1);
28
-
29
-
30
- steam64ID = '765' + (parseInt(steamID) + 61197960265728);
31
-
32
- callback( null, steam64ID );
33
-
34
- } else if ( IDFormat == 'steam32ID' ) {
35
-
36
- var middleNumber = steamID.substring(8, 9);
37
-
38
- steamID = steamID.replace('STEAM_0:1:', '');
39
- steamID = steamID.replace('STEAM_0:0:', '');
40
-
41
- steamID = new bignumber(steamID).times(2);
42
-
43
- var additionValue = new bignumber('76561197960265728').plus(middleNumber);
44
- steamID = new bignumber(steamID).plus(additionValue);
45
-
46
- steam64ID = steamID.c[0].toString() + steamID.c[1].toString();
47
- callback( null, steam64ID);
48
-
49
- } else if ( IDFormat == 'steam64ID' ) {
50
-
51
- callback( null, steamID);
52
-
53
- }
54
- });
55
- };
56
-
57
- exports.steam32ID = function( steamID, callback ) {
58
- determineIncomingFormat(steamID, function(err, IDFormat) {
59
-
60
- var steam32ID = '';
61
- var middleNumber = '';
62
-
63
- if ( IDFormat == 'steam64ID' ) {
64
-
65
- steam32ID = new bignumber(steamID).minus('76561197960265728')
66
-
67
- steam32ID = steam32ID / 2
68
-
69
- middleNumber = new bignumber(steamID).modulo(2)
70
-
71
- steam32ID = 'STEAM_0:' + middleNumber + ':' + parseInt(steam32ID);
72
-
73
- callback(null, steam32ID);
74
-
75
- } else if ( IDFormat == 'steam3ID' ) {
76
-
77
- exports.steam64ID( steamID, function(err, steam64ID) {
78
- exports.steam32ID( steam64ID, function(err, steam32ID) {
79
-
80
- callback( err, steam32ID )
81
-
82
- });
83
- });
84
-
85
- } else if ( IDFormat == 'steam32ID' ) {
86
-
87
- callback( null, steamID );
88
-
89
- }
90
- });
91
- };
92
-
93
- exports.steam3ID = function( steamID, callback ) {
94
- determineIncomingFormat(steamID, function(err, IDFormat) {
95
- if ( IDFormat == 'steam64ID' ) {
96
- var steam3ID = '';
97
-
98
- if ( steamID.toString().length == 17 ) {
99
-
100
- steam3ID = steamID.substring( steamID, 3 ) - 61197960265728;
101
- steam3ID = '[U:1:' + steam3ID.toString() + ']';
102
-
103
- callback ( null, steam3ID );
104
-
105
- }
106
-
107
- } else if ( IDFormat == 'steam32ID' ) {
108
-
109
- exports.steam64ID(steamID, function(err, steam64ID) {
110
- exports.steam3ID(steam64ID, function(err, steam3ID) {
111
-
112
- callback( err, steam3ID );
113
-
114
- });
115
- });
116
-
117
- } else if ( IDFormat == 'steam3ID') {
118
-
119
- callback( null, steamID );
120
-
121
- }
122
- });
123
- };
package/tests/tests.js DELETED
@@ -1,69 +0,0 @@
1
- var assert = require("assert");
2
- var convertTo = require('../index.js');
3
-
4
-
5
- describe('node-steam-conversions', function(){
6
-
7
- describe('steam32ID', function(){
8
- it('should should return the 32ID when given the 64ID', function(){
9
- convertTo.steam32ID( '76561197982486517', function (err, steam32ID) {
10
- assert.equal( 'STEAM_0:1:11110394', steam32ID );
11
- });
12
- })
13
-
14
- it('should should return the 32ID when given the 3ID', function(){
15
- convertTo.steam32ID( '[U:1:22220789]', function (err, steam32ID) {
16
- assert.equal( 'STEAM_0:1:11110394', steam32ID );
17
- });
18
- })
19
-
20
- it('should should return the 32ID when given the 32ID', function(){
21
- convertTo.steam32ID( 'STEAM_0:1:11110394', function (err, steam32ID) {
22
- assert.equal( 'STEAM_0:1:11110394', steam32ID );
23
- });
24
- })
25
-
26
- })
27
-
28
- describe('steam64ID', function(){
29
- it('should should return the 64ID when given the 3ID', function(){
30
- convertTo.steam64ID( '[U:1:22220789]', function (err, steam64ID) {
31
- assert.equal('76561197982486517', steam64ID);
32
- });
33
- })
34
-
35
- it('should should return the 64ID when given the 32ID', function(){
36
- convertTo.steam64ID( 'STEAM_0:1:11110394', function (err, steam64ID) {
37
- assert.equal('76561197982486517', steam64ID);
38
- });
39
- })
40
-
41
- it('should should return the 64ID when given the 64ID', function(){
42
- convertTo.steam64ID( '76561197982486517', function (err, steam64ID) {
43
- assert.equal('76561197982486517', steam64ID);
44
- });
45
- })
46
-
47
- })
48
- describe('steam3ID', function(){
49
- it('should return the 3ID when given the 64ID', function () {
50
- convertTo.steam3ID( '76561197982486517', function (err, steam3ID) {
51
- assert.equal('[U:1:22220789]', steam3ID);
52
- });
53
- })
54
-
55
- it('should return the 3ID when given the 32ID', function () {
56
- convertTo.steam3ID( 'STEAM_0:1:11110394', function (err, steam3ID) {
57
- assert.equal('[U:1:22220789]', steam3ID);
58
- });
59
- })
60
-
61
- it('should return the 3ID when given the 6ID', function () {
62
- convertTo.steam3ID( '[U:1:22220789]', function (err, steam3ID) {
63
- assert.equal('[U:1:22220789]', steam3ID);
64
- });
65
- })
66
-
67
- })
68
-
69
- });