socialblade-com-api
Advanced tools
Comparing version 1.0.2 to 1.1.0
{ | ||
"env": { | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"standard" | ||
], | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018 | ||
}, | ||
"rules": { | ||
} | ||
"env": { | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"extends": [ | ||
"standard" | ||
], | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018 | ||
}, | ||
"rules": { | ||
"quote-props": [ | ||
"error", | ||
"consistent-as-needed" | ||
] | ||
} | ||
} |
42
index.js
const axios = require('axios') | ||
const cheerio = require('cheerio') | ||
function cleanRows (rows) { | ||
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] | ||
return rows | ||
.map(row => row.replace(new RegExp(/(\t|\s|,|\+)+/, 'g'), '')) | ||
.filter(row => row && !days.includes(row)) | ||
} | ||
const { cleanRows, createArrayOfArrays, fillArray, convertArrayToObject } = require('./functions') | ||
function createArrayOfArrays (n) { | ||
const arrays = [] | ||
for (let i = 0; i < n; i++) { | ||
arrays.push([]) | ||
} | ||
return arrays | ||
} | ||
function fillArray (arrays, tableRows) { | ||
for (let i = 0, j = 0; i < tableRows.length; i++) { | ||
if (i % 7 === 0 && i !== 0) { | ||
j++ | ||
} | ||
arrays[j].push(tableRows[i]) | ||
} | ||
return arrays | ||
} | ||
function convertArrayToObject (arrays) { | ||
return arrays.map(array => { | ||
const [date, followersDelta, followers, followingDelta, following, postsDelta, posts] = array | ||
return { | ||
date: date.replace(/-/g, '/'), | ||
followersDelta: +followersDelta || 0, | ||
followers: +followers || 0, | ||
followingDelta: +followingDelta || 0, | ||
following: +following || 0, | ||
postsDelta: +postsDelta || 0, | ||
posts: +posts || 0 | ||
} | ||
}) | ||
} | ||
async function socialblade (username) { | ||
@@ -51,3 +13,3 @@ const html = await axios(`https://socialblade.com/twitter/user/${username}/monthly`) | ||
let arrays = createArrayOfArrays(tableRows.length / itemsPerRow) | ||
arrays = fillArray(arrays, tableRows) | ||
arrays = fillArray(arrays, tableRows, itemsPerRow) | ||
const array2obj = convertArrayToObject(arrays) | ||
@@ -54,0 +16,0 @@ return array2obj |
{ | ||
"name": "socialblade-com-api", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Unofficial APIs for Socialblade.com website.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
9304
8
154