New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

steam-market-pricing

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

steam-market-pricing - npm Package Compare versions

Comparing version 1.0.4 to 2.0.0

examples/multipleItems.js

95

index.js

@@ -1,2 +0,3 @@

var request = require('request');
const got = require('got');
const map = require('p-map');

@@ -8,82 +9,38 @@ /**

* @param {String} name - Item name, market hashed
* @param {Function} callback - Callback function(err, data)
* @param {number} [currency=1] - Currency code number, default USD (https://github.com/SteamRE/SteamKit/blob/master/Resources/SteamLanguage/enums.steamd#L696)
*/
exports.getItemPrice = function(appid, name, callback, currency) {
if (typeof callback !== 'function') {
throw new Error('No callback supplied');
async function getItemPrice(appid, name, currency = 1) {
const response = await got('http://steamcommunity.com//market/priceoverview', {
json: true,
query: {
currency: currency,
appid: appid,
market_hash_name: name
}
});
if (typeof currency !== 'number') {
currency = 1;
}
return { ...response.body, market_hash_name: name };
}
request({
uri: '/market/priceoverview',
baseUrl: 'http://steamcommunity.com/',
json: true,
qs: {
currency: currency,
appid: appid,
market_hash_name: name
}
}, function(err, response, body) {
if (!err && response.statusCode === 200) {
body.market_hash_name = name;
callback(null, body);
} else {
callback(err);
}
});
};
/**
* Retrieve price for list of items.
* Retrieve prices for list of items.
*
* @param {number} appid - Steam application id
* @param {Object} names - Item name, market hashed
* @param {Function} callback - Callback function(err, data)
* @param {Array} names - List of item names, market hashed
* @param {number} [currency=1] - Currency code number, default USD (https://github.com/SteamRE/SteamKit/blob/master/Resources/SteamLanguage/enums.steamd#L696)
* @param {number} [concurrency=1] - Number of concurrently running requests
*/
exports.getItemsPrice = function(appid, names, callback, currency) {
if (typeof callback !== 'function') {
throw new Error('No callback supplied');
}
async function getItemsPrices(appid, names, currency = 1, concurrency = 1) {
if (!Array.isArray(names)) {
if (typeof names === 'string') return getItemsPrices(appid, [names], currency);
throw new Error(`Invalid argument names, expected array got ${typeof names}`);
}
if (typeof currency !== 'number') {
currency = 1;
}
const result = {};
const items = await map(names, name => getItemPrice(appid, name, currency).catch(err => ({ success: false, market_hash_name: name, err })), { concurrency });
items.forEach(item => result[item.market_hash_name] = item);
if (typeof names !== 'object') {
if (typeof names === 'string') {
names = [names];
} else {
throw new Error('Non-object supplied');
}
}
return result;
}
var result = {};
names.forEach(function(name) {
request({
uri: '/market/priceoverview',
baseUrl: 'http://steamcommunity.com/',
json: true,
qs: {
currency: currency,
appid: appid,
market_hash_name: name
}
}, function(err, response, body) {
if (!err && response.statusCode === 200) {
result[name] = body;
} else {
result[name] = {'success': false};
}
if(Object.keys(result).length === names.length) {
callback(result);
}
});
});
};
module.exports = { getItemPrice, getItemsPrices };
{
"name": "steam-market-pricing",
"version": "1.0.4",
"version": "2.0.0",
"description": "Simple module that checks steam market prices",
"main": "index.js",
"scripts": {
"test": "ava"
},
"repository": {

@@ -34,4 +37,11 @@ "type": "git",

"dependencies": {
"request": "^2.65.0"
"got": "^8.0.1",
"p-map": "^1.2.0"
},
"devDependencies": {
"ava": "^0.24.0"
},
"engines": {
"node": ">= 7.6"
}
}

@@ -12,2 +12,4 @@ # Steam market price checker for Node.js

**Note** Latest release requires `async/await` (node >= 7.6) support to run to run, install 1.0.3 if your environment does not support it
## Usage

@@ -18,9 +20,5 @@

```js
var market = require('steam-market-pricing');
const market = require('steam-market-pricing');
market.getItemPrice(730, 'MP9 | Storm (Minimal Wear)', function(err, data) {
if(!err) {
console.log(data);
}
});
market.getItemPrice(730, 'MP9 | Storm (Minimal Wear)').then(item => console.log(item));
```

@@ -32,5 +30,5 @@

"success": true,
"lowest_price": "$0.06",
"volume": "237",
"median_price": "$0.04",
"lowest_price": "$0.05",
"volume": "108",
"median_price": "$0.03",
"market_hash_name": "MP9 | Storm (Minimal Wear)"

@@ -43,15 +41,10 @@ }

```js
var market = require('steam-market-pricing');
const market = require('steam-market-pricing');
var names = [
'MP9 | Storm (Minimal Wear)',
'Sawed-Off | Origami (Well-Worn)'
const names = [
'MP9 | Storm (Minimal Wear)',
'Sawed-Off | Origami (Well-Worn)'
];
market.getItemsPrice(730, names, function(data) {
//console.log(data);
for(var i in names) {
console.log(names[i] + ' median price: ' + data[names[i]]['median_price']);
}
});
market.getItemsPrices(730, names).then(items => names.forEach(name => console.log(`${name}: ${items[name].median_price}`)));
```

@@ -61,3 +54,3 @@

```
MP9 | Storm (Minimal Wear) median price: $0.05
MP9 | Storm (Minimal Wear) median price: $0.03
Sawed-Off | Origami (Well-Worn) median price: $0.09

@@ -69,7 +62,5 @@ ```

```js
var market = require('steam-market-pricing');
const market = require('steam-market-pricing');
market.getItemsPrice(730, 'MP9 | Storm (Minimal Wear)', function(data) {
console.log(data);
});
market.getItemsPrices(730, 'Sawed-Off | Origami (Well-Worn)').then(items => console.log(items));
```

@@ -82,5 +73,5 @@

"success": true,
"lowest_price": "$0.09",
"volume": "160",
"median_price": "$0.07"
"lowest_price": "$0.12",
"volume": "18",
"median_price": "$0.09"
}

@@ -90,27 +81,50 @@ }

**Note:** You can't handle response errors using getItemsPrice() method, any error will show as `success`: `false`.
Use with `await` for the best experience, check `test.js` for examples
## Methods
### getItemPrice(appid, name, callback, [currency])
### getItemPrice(appid, name, [currency = 1])
- `appid` - Steam application id
- `name` - Item name, market hashed
- `callback` - Callback function, called on response
- `err` - Request error, null if none
- `data` - JSON response data
- `currency` - Optional. Currency code (see: https://github.com/SteamRE/SteamKit/blob/master/Resources/SteamLanguage/enums.steamd#L696)
- `currency` - Optional. Currency code
Requests steam item market details
Requests steam item market details. Returns promise.
### getItemsPrice(appid, names, callback, [currency])
### getItemsPrices(appid, names[, currency = 1][, concurrency = 1])
- `appid` - Steam application id
- `names` - Array with item names, market hashed
- `callback` - Callback function, called on response
- `data` - JSON response data
- `currency` - Optional. Currency code (see: https://github.com/SteamRE/SteamKit/blob/master/Resources/SteamLanguage/enums.steamd#L696)
- `currency` - Optional. Currency code
- `currency` - Optional. Number of concurrent requests
Requests multiple steam items market details. Any error will be shown as `success`: `false`.
Requests multiple steam items market details. Returns promise.
**Note:** `getItemsPrices` will not throw, instead, it will attach the error into response object: `{ "success": false, "err": HTTPError }` check [GOT errors](https://www.npmjs.com/package/got#errors) for error descriptions
Currency codes can be found [here](https://github.com/SteamRE/SteamKit/blob/master/Resources/SteamLanguage/enums.steamd)
## License
MIT
```
The MIT License (MIT)
Copyright (c) 2015-2018 Arkadiusz Sygulski <arkadiusz@sygulski.pl>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc