Skip to content

Commit

Permalink
Add shared chunk.js file
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlancollins committed Dec 18, 2023
1 parent 2a41e57 commit fcc8fed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 32 deletions.
15 changes: 15 additions & 0 deletions scripts/chunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Divide an array into multiple smaller array
* @param {Array} input
* @param {number} size
* @return {Array<Array>}
*/
export function chunk(input, size) {
size = size < 1 ? 10 : size;
const pages = Math.ceil(input.length / size);
const final = [];
for (let index = 0; index < pages; index++) {
final.push(input.slice(index * size, (index + 1) * size));
}
return final;
}
17 changes: 1 addition & 16 deletions scripts/updateGithub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { componentsSchema, templatesSchema, toolsSchema } from '../src/lib/schem
import components from '../src/routes/components/components.json' assert { type: 'json' };
import templates from '../src/routes/templates/templates.json' assert { type: 'json' };
import tools from '../src/routes/tools/tools.json' assert { type: 'json' };
import { chunk } from './chunk.js';

const ghGraphQlUrl = 'https://api.github.com/graphql';
const githubNameRegexp = new RegExp(
Expand Down Expand Up @@ -53,22 +54,6 @@ function ghRepoGraphQl(url) {
return `${identifier}: repository(name: "${repo}", owner: "${owner}"){url stargazerCount}`;
}

/**
* Divide an array into multiple smaller array
* @param {Array} input
* @param {number} size
* @return {Array<Array>}
*/
function chunk(input, size) {
size = size < 1 ? 10 : size;
const pages = Math.ceil(input.length / size);
const final = [];
for (let index = 0; index < pages; index++) {
final.push(input.slice(index * size, (index + 1) * size));
}
return final;
}

/**
* Get the number of stars for all GitHub repositories.
* The result is a Map where the key the repo name and the value is the number of stars.
Expand Down
17 changes: 1 addition & 16 deletions scripts/updateGitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { componentsSchema, templatesSchema, toolsSchema } from '../src/lib/schem
import components from '../src/routes/components/components.json' assert { type: 'json' };
import templates from '../src/routes/templates/templates.json' assert { type: 'json' };
import tools from '../src/routes/tools/tools.json' assert { type: 'json' };
import { chunk } from './chunk.js';

const gitlabGraphQlUrl = 'https://gitlab.com/api/graphql';
const gitlabNameRegExp = new RegExp('https://gitlab.com/([\\w-]+/[\\w-]+)');
Expand Down Expand Up @@ -38,22 +39,6 @@ function getAllGitlabRepos() {
return repos.filter((url) => url && gitlabNameRegExp.test(url));
}

/**
* Divide an array into multiple smaller array
* @param {string[]} input
* @param {number} size
* @return {string[][]}
*/
function chunk(input, size) {
size = size < 1 ? 10 : size;
const pages = Math.ceil(input.length / size);
const final = [];
for (let index = 0; index < pages; index++) {
final.push(input.slice(index * size, (index + 1) * size));
}
return final;
}

/**
* @param {string} url
*/
Expand Down

0 comments on commit fcc8fed

Please sign in to comment.