socialblade-com-api
Advanced tools
Comparing version 2.2.3 to 3.0.0
{ | ||
"env": { | ||
"commonjs": true, | ||
"es6": true, | ||
"es2021": true, | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"extends": [ | ||
"standard" | ||
], | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"extends": "google", | ||
"parserOptions": { | ||
"ecmaVersion": 2018 | ||
"ecmaVersion": 12 | ||
}, | ||
"rules": { | ||
"quote-props": [ | ||
"error", | ||
"consistent-as-needed" | ||
] | ||
"max-len": [ | ||
"error", 100 | ||
], | ||
"object-curly-spacing": [ | ||
"error", "always" | ||
], | ||
"space-infix-ops": "error" | ||
} | ||
} | ||
} |
145
functions.js
const cheerio = require('cheerio') | ||
const cheerio = require('cheerio'); | ||
const validSources = ['twitter', 'instagram', 'facebook', 'youtube'] | ||
const validSources = ['twitter', 'instagram', 'facebook', 'youtube']; | ||
function isValidSource (source) { | ||
return validSources.includes(source) | ||
/** | ||
* Check if the source is valid | ||
* @param {string} source Social source | ||
* @return {boolean} returns if the source is valid | ||
*/ | ||
function isValidSource(source) { | ||
return validSources.includes(source); | ||
} | ||
function generateUrl (urlPrefix, source, username) { | ||
/** | ||
* Generate url for Socialblade from source and username | ||
* @param {string} source Social source | ||
* @param {string} username Social username | ||
* @return {string} generated URL for socialblade with source and username | ||
*/ | ||
function generateUrl(source, username) { | ||
const userUrlCriteria = { | ||
facebook: 'page', | ||
youtube: 'channel' | ||
} | ||
const userUrl = userUrlCriteria[source] || 'user' | ||
const urlSuffix = source === 'facebook' ? '' : '/monthly' | ||
return `${urlPrefix}https://socialblade.com/${source}/${userUrl}/${username}${urlSuffix}` | ||
youtube: 'channel', | ||
}; | ||
const userUrl = userUrlCriteria[source] || 'user'; | ||
const urlSuffix = source === 'facebook' ? '' : '/monthly'; | ||
return `https://socialblade.com/${source}/${userUrl}/${username}${urlSuffix}`; | ||
} | ||
function getOutput (data, source) { | ||
const $ = cheerio.load(data) | ||
/** | ||
* Get table and charts data from Socialblade | ||
* @param {string} data html data from Socialblade | ||
* @param {string} source Social source | ||
* @return {object} | ||
*/ | ||
function getOutput(data, source) { | ||
const $ = cheerio.load(data); | ||
// Table for Twitter, Instagram, Facebook, Youtube | ||
let table = $('#socialblade-user-content > div:nth-child(5)').text().split('\n') | ||
let table = $('#socialblade-user-content > div:nth-child(5)').text().split('\n'); | ||
if (source === 'youtube') { | ||
table = $('#socialblade-user-content').text().split(/\s+ESTIMATED EARNINGS\n/)[1].split(/\s+Daily Averages /)[0].split('\n') | ||
// eslint-disable-next-line max-len | ||
table = $('#socialblade-user-content').text().split(/\s+ESTIMATED EARNINGS\n/)[1].split(/\s+Daily Averages /)[0].split('\n'); | ||
} | ||
// Charts for Twitter, Instagram, Youtube | ||
let charts = [] | ||
let charts = []; | ||
if (source !== 'facebook') { | ||
charts = $('script').contents().get(4).data.split('\n') | ||
charts = $('script').contents().get(4).data.split('\n'); | ||
} | ||
return { table, charts } | ||
return { table, charts }; | ||
} | ||
function cleanRows (table, charts) { | ||
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] | ||
// eslint-disable-next-line require-jsdoc | ||
function cleanRows(table, charts) { | ||
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; | ||
const tableRows = table | ||
.map(row => row.replace(/(\t|\s|,|\+)+/g, '')) | ||
.filter(row => row && !days.includes(row)) | ||
.map((row) => row.replace(/(\t|\s|,|\+)+/g, '')) | ||
.filter((row) => row && !days.includes(row)); | ||
const chartsRows = charts | ||
.filter(item => /^title: { text|^series:/g.test(item.trim())) | ||
.map(item => item.trim().replace(/title: { text: |'|\\| },|series: | }],/g, '')) | ||
.map(item => item.includes('[{ name:') ? item.split('data: ')[1] : item) | ||
return { tableRows, chartsRows } | ||
.filter((item) => /^title: { text|^series:/g.test(item.trim())) | ||
.map((item) => item.trim().replace(/title: { text: |'|\\| },|series: | }],/g, '')) | ||
.map((item) => item.includes('[{ name:') ? item.split('data: ')[1] : item); | ||
return { tableRows, chartsRows }; | ||
} | ||
function createArrayOfArrays (n) { | ||
const arrays = [] | ||
/** | ||
* Create an array of arrays | ||
* @param {number} n length of array | ||
* @return {array} Array | ||
*/ | ||
function createArrayOfArrays(n) { | ||
const arrays = []; | ||
for (let i = 0; i < n; i++) { | ||
arrays.push([]) | ||
arrays.push([]); | ||
} | ||
return arrays | ||
return arrays; | ||
} | ||
function fillArray (arrays, tableRows, itemsPerRow) { | ||
// eslint-disable-next-line require-jsdoc | ||
function fillArray(arrays, tableRows, itemsPerRow) { | ||
for (let i = 0, j = 0; i < tableRows.length; i++) { | ||
if (i % itemsPerRow === 0 && i !== 0) { | ||
j++ | ||
j++; | ||
} | ||
arrays[j].push(tableRows[i]) | ||
arrays[j].push(tableRows[i]); | ||
} | ||
return arrays | ||
return arrays; | ||
} | ||
function convertArrayToObject (source, arrays) { | ||
return arrays.map(array => { | ||
const [col1, col2, col3, col4, col5, col6, col7] = array | ||
let parsed | ||
// eslint-disable-next-line require-jsdoc | ||
function convertArrayToObject(source, arrays) { | ||
return arrays.map((array) => { | ||
const [col1, col2, col3, col4, col5, col6, col7] = array; | ||
let parsed; | ||
switch (source) { | ||
@@ -79,4 +105,4 @@ case 'twitter': | ||
postsDelta: +col6 || 0, | ||
posts: +col7 || 0 | ||
} | ||
posts: +col7 || 0, | ||
}; | ||
case 'facebook': | ||
@@ -88,4 +114,4 @@ return { | ||
talkingAboutDelta: +col4 || 0, | ||
talkingAbout: +col5 || 0 | ||
} | ||
talkingAbout: +col5 || 0, | ||
}; | ||
case 'youtube': | ||
@@ -97,31 +123,34 @@ return { | ||
viewsDelta: +col4 || 0, | ||
views: +col5 || 0 | ||
} | ||
views: +col5 || 0, | ||
}; | ||
case 'charts': | ||
default: | ||
parsed = JSON.parse(col2) | ||
parsed = JSON.parse(col2); | ||
// [[Timestamp, Number], [...], ...] | ||
parsed = (parsed || []).map(item => ({ date: getDate(item[0]), value: item[1] })) | ||
parsed = (parsed || []).map((item) => ({ date: getDate(item[0]), value: item[1] })); | ||
return { | ||
id: generateId(col1), | ||
title: col1, | ||
data: parsed | ||
} | ||
data: parsed, | ||
}; | ||
} | ||
}) | ||
}); | ||
} | ||
function getDate (str) { | ||
return new Date(str).toISOString().split('T')[0].replace(/-/g, '/') | ||
// eslint-disable-next-line require-jsdoc | ||
function getDate(str) { | ||
return new Date(str).toISOString().split('T')[0].replace(/-/g, '/'); | ||
} | ||
function generateId (str) { | ||
const splitted = str.split(/ for |\(/) | ||
// eslint-disable-next-line require-jsdoc | ||
function generateId(str) { | ||
const splitted = str.split(/ for |\(/); | ||
return `${splitted[2] || ''.slice(0, -1)}${splitted[0]}` | ||
.toLowerCase() | ||
.replace(/\s|\)/g, '-') | ||
.toLowerCase() | ||
.replace(/\s|\)/g, '-'); | ||
} | ||
function convertUnit (str) { | ||
return str.replace('K', '000').replace('M', '000000') | ||
// eslint-disable-next-line require-jsdoc | ||
function convertUnit(str) { | ||
return str.replace('K', '000').replace('M', '000000'); | ||
} | ||
@@ -137,3 +166,3 @@ | ||
fillArray, | ||
convertArrayToObject | ||
} | ||
convertArrayToObject, | ||
}; |
69
index.js
@@ -1,2 +0,2 @@ | ||
const axios = require('axios') | ||
const puppeteer = require('puppeteer'); | ||
@@ -11,40 +11,49 @@ const { | ||
isValidSource, | ||
validSources | ||
} = require('./functions') | ||
validSources, | ||
} = require('./functions'); | ||
let retries = 2 | ||
function callSocialblade (url) { | ||
return axios.get(url) | ||
/** | ||
* Get content from a Socialblade page | ||
* @param {string} url The URL of Socialblade page | ||
* @return {string} Content of the page | ||
*/ | ||
async function callSocialblade(url) { | ||
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
// eslint-disable-next-line max-len | ||
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'); | ||
await page.goto(url); | ||
const content = await page.content(); | ||
await browser.close(); | ||
return content; | ||
} | ||
async function socialblade (urlPrefix, source, username) { | ||
/** | ||
* Return data from Socialblade | ||
* @param {string} source The social source. Valid inputs: twitter, instagram, facebook, youtube | ||
* @param {string} username The social username | ||
* @return {object} data from Socialblade | ||
*/ | ||
async function socialblade(source, username) { | ||
try { | ||
if (!isValidSource(source)) { | ||
throw Error(`Invalid source. Valid sources are: ${validSources.join(', ')}`) | ||
throw Error(`Invalid source. Valid sources are: ${validSources.join(', ')}`); | ||
} | ||
const url = generateUrl(urlPrefix, source, username) | ||
const html = await callSocialblade(url) | ||
const { table, charts } = getOutput(html.data, source) | ||
const { tableRows, chartsRows } = cleanRows(table, charts) | ||
const itemsPerRow = { twitter: 7, instagram: 7, facebook: 5, youtube: 6 } | ||
let tableArrays = createArrayOfArrays(tableRows.length / itemsPerRow[source]) | ||
tableArrays = fillArray(tableArrays, tableRows, itemsPerRow[source]) | ||
const tableArrayOfObjects = convertArrayToObject(source, tableArrays) | ||
let chartsArrays = createArrayOfArrays(chartsRows.length / 2) | ||
chartsArrays = fillArray(chartsArrays, chartsRows, 2) | ||
const chartsArrayOfObjects = convertArrayToObject('charts', chartsArrays) | ||
return { table: tableArrayOfObjects, charts: chartsArrayOfObjects } | ||
const url = generateUrl(source, username); | ||
const html = await callSocialblade(url); | ||
const { table, charts } = getOutput(html, source); | ||
const { tableRows, chartsRows } = cleanRows(table, charts); | ||
const itemsPerRow = { twitter: 7, instagram: 7, facebook: 5, youtube: 6 }; | ||
let tableArrays = createArrayOfArrays(tableRows.length / itemsPerRow[source]); | ||
tableArrays = fillArray(tableArrays, tableRows, itemsPerRow[source]); | ||
const tableArrayOfObjects = convertArrayToObject(source, tableArrays); | ||
let chartsArrays = createArrayOfArrays(chartsRows.length / 2); | ||
chartsArrays = fillArray(chartsArrays, chartsRows, 2); | ||
const chartsArrayOfObjects = convertArrayToObject('charts', chartsArrays); | ||
return { table: tableArrayOfObjects, charts: chartsArrayOfObjects }; | ||
} catch (err) { | ||
console.log(err.response ? err.response.data : err) | ||
if (retries > 0) { | ||
retries-- | ||
console.log('Failed once, retrying...') | ||
return socialblade(urlPrefix, source, username) | ||
} else { | ||
console.log('Request failed too many times, aborting.') | ||
} | ||
console.log(err.message); | ||
} | ||
} | ||
exports.socialblade = socialblade | ||
exports.socialblade = socialblade; |
{ | ||
"name": "socialblade-com-api", | ||
"version": "2.2.3", | ||
"version": "3.0.0", | ||
"description": "Unofficial APIs for Socialblade.com website.", | ||
@@ -36,14 +36,10 @@ "main": "index.js", | ||
"dependencies": { | ||
"axios": "^0.21.0", | ||
"cheerio": "^1.0.0-rc.3" | ||
"cheerio": "^1.0.0-rc.12", | ||
"puppeteer": "^18.0.4" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^7.1.0", | ||
"eslint-config-standard": "^16.0.2", | ||
"eslint-plugin-import": "^2.20.2", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^5.1.0", | ||
"eslint-plugin-standard": "^5.0.0", | ||
"mocha": "^9.0.1" | ||
"eslint": "^8.23.1", | ||
"eslint-config-google": "^0.14.0", | ||
"mocha": "^10.0.0" | ||
} | ||
} |
@@ -10,5 +10,4 @@ # Socialblade.com unofficial APIs | ||
### Params of `socialblade` function | ||
1. `urlprefix`: Socialblade website is protected by Cloudflare, I use Scraperapi.com as prefix to bypass the blocks. | ||
2. `source`: [one of the followings](https://github.com/DavideViolante/socialblade-com-api/blob/master/functions.js#L4). | ||
3. `username`: username on the specified source. | ||
1. `source`: [one of the followings](https://github.com/DavideViolante/socialblade-com-api/blob/master/functions.js#L4). | ||
2. `username`: username on the specified source. | ||
@@ -21,3 +20,3 @@ ### Example | ||
try { | ||
const response = await socialblade('http://api.scraperapi.com?api_key=<YOUR_API_KEY>&url=', 'twitter', 'barackobama') | ||
const response = await socialblade('twitter', 'barackobama') | ||
} catch (err) { | ||
@@ -24,0 +23,0 @@ console.error(err) |
197
test/test.js
@@ -1,3 +0,4 @@ | ||
const assert = require('assert') | ||
const { cleanRows, convertArrayToObject, createArrayOfArrays, fillArray, generateUrl } = require('../functions') | ||
/* eslint-disable max-len */ | ||
const assert = require('assert'); | ||
const { cleanRows, convertArrayToObject, createArrayOfArrays, fillArray, generateUrl } = require('../functions'); | ||
@@ -7,3 +8,3 @@ const mockTableToClean = [ | ||
' Mon', '\t ', ' ', '\t ', | ||
' --', ' 116,620,154 \t\t'] | ||
' --', ' 116,620,154 \t\t']; | ||
const mockChartsToClean = [ | ||
@@ -15,17 +16,17 @@ '', | ||
' ', | ||
" Highcharts.chart('graph-twitter-weekly-change-followers-container', {", | ||
" chart: { type: 'area', zoomType: 'xy', resetZoomButton: { position: { x: 0, y: -52 } } }, ", | ||
' Highcharts.chart(\'graph-twitter-weekly-change-followers-container\', {', | ||
' chart: { type: \'area\', zoomType: \'xy\', resetZoomButton: { position: { x: 0, y: -52 } } }, ', | ||
' credits: { enabled: false },\t\t ', | ||
" title: { text: 'Weekly Followers Gained for \\'Nike\\'' },", | ||
" yAxis: { title: { text: 'Followers' }, minorGridLineWidth: 1, gridLineWidth: 1, alternateGridColor: null, },", | ||
" series: [{ name: '', showInLegend: false, animation: false, color: '#c84329', lineWidth: 2, data: [[1466481600000,11962],[1467000000000,14270],[1467604800000,13884],[1468209600000,14675],[1468814400000,25269]] }],", | ||
' title: { text: \'Weekly Followers Gained for \\\'Nike\\\'\' },', | ||
' yAxis: { title: { text: \'Followers\' }, minorGridLineWidth: 1, gridLineWidth: 1, alternateGridColor: null, },', | ||
' series: [{ name: \'\', showInLegend: false, animation: false, color: \'#c84329\', lineWidth: 2, data: [[1466481600000,11962],[1467000000000,14270],[1467604800000,13884],[1468209600000,14675],[1468814400000,25269]] }],', | ||
' });\t\t ', | ||
''] | ||
const mockTableArrayOfArrays = [[], [], []] | ||
const mockChartsArrayOfArrays = [[], []] | ||
'']; | ||
const mockTableArrayOfArrays = [[], [], []]; | ||
const mockChartsArrayOfArrays = [[], []]; | ||
const mockTableRows = [ | ||
'2020-04-27', '--', '116620154', | ||
'2020-04-28', '--', '116720154', | ||
'2020-04-29', '--', '116820154' | ||
] | ||
'2020-04-29', '--', '116820154', | ||
]; | ||
const mockChartsRows = [ | ||
@@ -35,102 +36,102 @@ 'Weekly Followers Gained for Nike', | ||
'Weekly Following Gained for Nike', | ||
'[[1466481600000,1196],[1467000000000,1427],[1467604800000,1388],[1468209600000,1467],[1468814400000,2526]]' | ||
] | ||
'[[1466481600000,1196],[1467000000000,1427],[1467604800000,1388],[1468209600000,1467],[1468814400000,2526]]', | ||
]; | ||
const mockTableFilledArray = [ | ||
['2020-04-27', '--', '116620154', '1', '4', '7', '+1'], | ||
['2020-04-28', '--', '116720154', '2', '5', '8', '-1'], | ||
['2020-04-29', '--', '116820154', '3', '6', '9', '+2'] | ||
] | ||
['2020-04-29', '--', '116820154', '3', '6', '9', '+2'], | ||
]; | ||
const mockChartsFilledArray = [ | ||
['Weekly Followers Gained for Nike', '[[1466481600000,11962],[1467000000000,14270],[1467604800000,13884],[1468209600000,14675],[1468814400000,25269]]'], | ||
['Weekly Following Gained for Nike', '[[1466481600000,1196],[1467000000000,1427],[1467604800000,1388],[1468209600000,1467],[1468814400000,2526]]'] | ||
] | ||
['Weekly Following Gained for Nike', '[[1466481600000,1196],[1467000000000,1427],[1467604800000,1388],[1468209600000,1467],[1468814400000,2526]]'], | ||
]; | ||
describe('Tests for socialblade-com-api', () => { | ||
it('should generate the url', () => { | ||
const url1 = generateUrl('prefix', 'twitter', 'barackobama') | ||
const url2 = generateUrl('prefix', 'facebook', 'barackobama') | ||
assert.strictEqual(url1, 'prefixhttps://socialblade.com/twitter/user/barackobama/monthly') | ||
assert.strictEqual(url2, 'prefixhttps://socialblade.com/facebook/page/barackobama') | ||
}) | ||
const url1 = generateUrl('twitter', 'barackobama'); | ||
const url2 = generateUrl('facebook', 'barackobama'); | ||
assert.strictEqual(url1, 'https://socialblade.com/twitter/user/barackobama/monthly'); | ||
assert.strictEqual(url2, 'https://socialblade.com/facebook/page/barackobama'); | ||
}); | ||
it('should clean an array from unwanted chars', () => { | ||
const { tableRows, chartsRows } = cleanRows(mockTableToClean, mockChartsToClean) | ||
assert.strictEqual(tableRows.length, 3) | ||
assert.strictEqual(tableRows[0], '2020-04-27') | ||
assert.strictEqual(tableRows[1], '--') | ||
assert.strictEqual(tableRows[2], '116620154') | ||
assert.strictEqual(chartsRows.length, 2) | ||
assert.strictEqual(chartsRows[0], 'Weekly Followers Gained for Nike') | ||
assert.strictEqual(chartsRows[1], '[[1466481600000,11962],[1467000000000,14270],[1467604800000,13884],[1468209600000,14675],[1468814400000,25269]]') | ||
}) | ||
const { tableRows, chartsRows } = cleanRows(mockTableToClean, mockChartsToClean); | ||
assert.strictEqual(tableRows.length, 3); | ||
assert.strictEqual(tableRows[0], '2020-04-27'); | ||
assert.strictEqual(tableRows[1], '--'); | ||
assert.strictEqual(tableRows[2], '116620154'); | ||
assert.strictEqual(chartsRows.length, 2); | ||
assert.strictEqual(chartsRows[0], 'Weekly Followers Gained for Nike'); | ||
assert.strictEqual(chartsRows[1], '[[1466481600000,11962],[1467000000000,14270],[1467604800000,13884],[1468209600000,14675],[1468814400000,25269]]'); | ||
}); | ||
it('should create an array of N arrays', () => { | ||
const arrayOfArrays = createArrayOfArrays(3) | ||
assert.strictEqual(arrayOfArrays.length, 3) | ||
assert.strictEqual(arrayOfArrays[0].length, 0) | ||
assert.strictEqual(arrayOfArrays[1].length, 0) | ||
assert.strictEqual(arrayOfArrays[2].length, 0) | ||
}) | ||
const arrayOfArrays = createArrayOfArrays(3); | ||
assert.strictEqual(arrayOfArrays.length, 3); | ||
assert.strictEqual(arrayOfArrays[0].length, 0); | ||
assert.strictEqual(arrayOfArrays[1].length, 0); | ||
assert.strictEqual(arrayOfArrays[2].length, 0); | ||
}); | ||
it('should fill arrays inside an array', () => { | ||
const tableFilledArray = fillArray(mockTableArrayOfArrays, mockTableRows, 3) | ||
assert.strictEqual(tableFilledArray.length, 3) | ||
assert.strictEqual(tableFilledArray[0].length, 3) | ||
assert.strictEqual(tableFilledArray[1].length, 3) | ||
assert.strictEqual(tableFilledArray[2].length, 3) | ||
assert.strictEqual(tableFilledArray[0][0], '2020-04-27') | ||
assert.strictEqual(tableFilledArray[0][1], '--') | ||
assert.strictEqual(tableFilledArray[0][2], '116620154') | ||
assert.strictEqual(tableFilledArray[1][0], '2020-04-28') | ||
assert.strictEqual(tableFilledArray[1][1], '--') | ||
assert.strictEqual(tableFilledArray[1][2], '116720154') | ||
assert.strictEqual(tableFilledArray[2][0], '2020-04-29') | ||
assert.strictEqual(tableFilledArray[2][1], '--') | ||
assert.strictEqual(tableFilledArray[2][2], '116820154') | ||
const chartsFilledArray = fillArray(mockChartsArrayOfArrays, mockChartsRows, 2) | ||
assert.strictEqual(chartsFilledArray.length, 2) | ||
assert.strictEqual(chartsFilledArray[0].length, 2) | ||
assert.strictEqual(chartsFilledArray[1].length, 2) | ||
assert.strictEqual(chartsFilledArray[0][0], 'Weekly Followers Gained for Nike') | ||
assert.strictEqual(chartsFilledArray[0][1], '[[1466481600000,11962],[1467000000000,14270],[1467604800000,13884],[1468209600000,14675],[1468814400000,25269]]') | ||
assert.strictEqual(chartsFilledArray[1][0], 'Weekly Following Gained for Nike') | ||
assert.strictEqual(chartsFilledArray[1][1], '[[1466481600000,1196],[1467000000000,1427],[1467604800000,1388],[1468209600000,1467],[1468814400000,2526]]') | ||
}) | ||
const tableFilledArray = fillArray(mockTableArrayOfArrays, mockTableRows, 3); | ||
assert.strictEqual(tableFilledArray.length, 3); | ||
assert.strictEqual(tableFilledArray[0].length, 3); | ||
assert.strictEqual(tableFilledArray[1].length, 3); | ||
assert.strictEqual(tableFilledArray[2].length, 3); | ||
assert.strictEqual(tableFilledArray[0][0], '2020-04-27'); | ||
assert.strictEqual(tableFilledArray[0][1], '--'); | ||
assert.strictEqual(tableFilledArray[0][2], '116620154'); | ||
assert.strictEqual(tableFilledArray[1][0], '2020-04-28'); | ||
assert.strictEqual(tableFilledArray[1][1], '--'); | ||
assert.strictEqual(tableFilledArray[1][2], '116720154'); | ||
assert.strictEqual(tableFilledArray[2][0], '2020-04-29'); | ||
assert.strictEqual(tableFilledArray[2][1], '--'); | ||
assert.strictEqual(tableFilledArray[2][2], '116820154'); | ||
const chartsFilledArray = fillArray(mockChartsArrayOfArrays, mockChartsRows, 2); | ||
assert.strictEqual(chartsFilledArray.length, 2); | ||
assert.strictEqual(chartsFilledArray[0].length, 2); | ||
assert.strictEqual(chartsFilledArray[1].length, 2); | ||
assert.strictEqual(chartsFilledArray[0][0], 'Weekly Followers Gained for Nike'); | ||
assert.strictEqual(chartsFilledArray[0][1], '[[1466481600000,11962],[1467000000000,14270],[1467604800000,13884],[1468209600000,14675],[1468814400000,25269]]'); | ||
assert.strictEqual(chartsFilledArray[1][0], 'Weekly Following Gained for Nike'); | ||
assert.strictEqual(chartsFilledArray[1][1], '[[1466481600000,1196],[1467000000000,1427],[1467604800000,1388],[1468209600000,1467],[1468814400000,2526]]'); | ||
}); | ||
it('should convert an array to object', () => { | ||
const tableConvertedArray = convertArrayToObject('twitter', mockTableFilledArray) | ||
assert.strictEqual(tableConvertedArray.length, 3) | ||
assert.strictEqual(tableConvertedArray[0].date, '2020/04/27') | ||
assert.strictEqual(tableConvertedArray[0].followersDelta, 0) | ||
assert.strictEqual(tableConvertedArray[0].followers, 116620154) | ||
assert.strictEqual(tableConvertedArray[0].followingDelta, 1) | ||
assert.strictEqual(tableConvertedArray[0].following, 4) | ||
assert.strictEqual(tableConvertedArray[0].postsDelta, 7) | ||
assert.strictEqual(tableConvertedArray[0].posts, 1) | ||
assert.strictEqual(tableConvertedArray[1].date, '2020/04/28') | ||
assert.strictEqual(tableConvertedArray[1].followersDelta, 0) | ||
assert.strictEqual(tableConvertedArray[1].followers, 116720154) | ||
assert.strictEqual(tableConvertedArray[1].followingDelta, 2) | ||
assert.strictEqual(tableConvertedArray[1].following, 5) | ||
assert.strictEqual(tableConvertedArray[1].postsDelta, 8) | ||
assert.strictEqual(tableConvertedArray[1].posts, -1) | ||
assert.strictEqual(tableConvertedArray[2].date, '2020/04/29') | ||
assert.strictEqual(tableConvertedArray[2].followersDelta, 0) | ||
assert.strictEqual(tableConvertedArray[2].followers, 116820154) | ||
assert.strictEqual(tableConvertedArray[2].followingDelta, 3) | ||
assert.strictEqual(tableConvertedArray[2].following, 6) | ||
assert.strictEqual(tableConvertedArray[2].postsDelta, 9) | ||
assert.strictEqual(tableConvertedArray[2].posts, 2) | ||
const chartsConvertedArray = convertArrayToObject('charts', mockChartsFilledArray) | ||
assert.strictEqual(chartsConvertedArray[0].id, 'weekly-followers-gained') | ||
assert.strictEqual(chartsConvertedArray[0].title, 'Weekly Followers Gained for Nike') | ||
assert.strictEqual(chartsConvertedArray[0].data.length, 5) | ||
assert.strictEqual(chartsConvertedArray[0].data[0].date, '2016/06/21') | ||
assert.strictEqual(chartsConvertedArray[0].data[0].value, 11962) | ||
assert.strictEqual(chartsConvertedArray[1].id, 'weekly-following-gained') | ||
assert.strictEqual(chartsConvertedArray[1].title, 'Weekly Following Gained for Nike') | ||
assert.strictEqual(chartsConvertedArray[1].data.length, 5) | ||
assert.strictEqual(chartsConvertedArray[1].data[0].date, '2016/06/21') | ||
assert.strictEqual(chartsConvertedArray[1].data[0].value, 1196) | ||
}) | ||
}) | ||
const tableConvertedArray = convertArrayToObject('twitter', mockTableFilledArray); | ||
assert.strictEqual(tableConvertedArray.length, 3); | ||
assert.strictEqual(tableConvertedArray[0].date, '2020/04/27'); | ||
assert.strictEqual(tableConvertedArray[0].followersDelta, 0); | ||
assert.strictEqual(tableConvertedArray[0].followers, 116620154); | ||
assert.strictEqual(tableConvertedArray[0].followingDelta, 1); | ||
assert.strictEqual(tableConvertedArray[0].following, 4); | ||
assert.strictEqual(tableConvertedArray[0].postsDelta, 7); | ||
assert.strictEqual(tableConvertedArray[0].posts, 1); | ||
assert.strictEqual(tableConvertedArray[1].date, '2020/04/28'); | ||
assert.strictEqual(tableConvertedArray[1].followersDelta, 0); | ||
assert.strictEqual(tableConvertedArray[1].followers, 116720154); | ||
assert.strictEqual(tableConvertedArray[1].followingDelta, 2); | ||
assert.strictEqual(tableConvertedArray[1].following, 5); | ||
assert.strictEqual(tableConvertedArray[1].postsDelta, 8); | ||
assert.strictEqual(tableConvertedArray[1].posts, -1); | ||
assert.strictEqual(tableConvertedArray[2].date, '2020/04/29'); | ||
assert.strictEqual(tableConvertedArray[2].followersDelta, 0); | ||
assert.strictEqual(tableConvertedArray[2].followers, 116820154); | ||
assert.strictEqual(tableConvertedArray[2].followingDelta, 3); | ||
assert.strictEqual(tableConvertedArray[2].following, 6); | ||
assert.strictEqual(tableConvertedArray[2].postsDelta, 9); | ||
assert.strictEqual(tableConvertedArray[2].posts, 2); | ||
const chartsConvertedArray = convertArrayToObject('charts', mockChartsFilledArray); | ||
assert.strictEqual(chartsConvertedArray[0].id, 'weekly-followers-gained'); | ||
assert.strictEqual(chartsConvertedArray[0].title, 'Weekly Followers Gained for Nike'); | ||
assert.strictEqual(chartsConvertedArray[0].data.length, 5); | ||
assert.strictEqual(chartsConvertedArray[0].data[0].date, '2016/06/21'); | ||
assert.strictEqual(chartsConvertedArray[0].data[0].value, 11962); | ||
assert.strictEqual(chartsConvertedArray[1].id, 'weekly-following-gained'); | ||
assert.strictEqual(chartsConvertedArray[1].title, 'Weekly Following Gained for Nike'); | ||
assert.strictEqual(chartsConvertedArray[1].data.length, 5); | ||
assert.strictEqual(chartsConvertedArray[1].data[0].date, '2016/06/21'); | ||
assert.strictEqual(chartsConvertedArray[1].data[0].value, 1196); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
19421
3
10
354
62
1
+ Addedpuppeteer@^18.0.4
+ Added@types/node@22.9.3(transitive)
+ Added@types/yauzl@2.10.3(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedbuffer-crc32@0.2.13(transitive)
+ Addedchownr@1.1.4(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcross-fetch@3.1.5(transitive)
+ Addeddebug@4.3.44.3.7(transitive)
+ Addeddevtools-protocol@0.0.1045489(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedextract-zip@2.0.1(transitive)
+ Addedfd-slicer@1.1.0(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedget-stream@5.2.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedmkdirp-classic@0.5.3(transitive)
+ Addedms@2.1.22.1.3(transitive)
+ Addednode-fetch@2.6.7(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpend@1.2.0(transitive)
+ Addedprogress@2.0.3(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedpuppeteer@18.2.1(transitive)
+ Addedpuppeteer-core@18.2.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedtar-fs@2.1.1(transitive)
+ Addedtar-stream@2.2.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedunbzip2-stream@1.4.3(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedws@8.9.0(transitive)
+ Addedyauzl@2.10.0(transitive)
- Removedaxios@^0.21.0
- Removedaxios@0.21.4(transitive)
- Removedfollow-redirects@1.15.9(transitive)
Updatedcheerio@^1.0.0-rc.12