Change endpoint from persons to people

This commit is contained in:
xfarrow
2025-03-23 21:00:08 +01:00
parent 4ae263662c
commit d005193f63
7158 changed files with 700476 additions and 735 deletions

View File

@ -0,0 +1,86 @@
const fs = require('fs');
const flatten = require('lodash/flatten');
const os = require('os');
const path = require('path');
const { promisify } = require('util');
// Promisify common fs functions.
const stat = promisify(fs.stat);
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
const readdir = promisify(fs.readdir);
const mkdir = promisify(fs.mkdir);
function existsSync(path) {
try {
fs.accessSync(path);
return true;
} catch (e) {
return false;
}
}
/**
* Creates a temporary directory and returns it path.
*
* @returns {Promise<string>}
*/
function createTemp() {
return promisify(fs.mkdtemp)(`${os.tmpdir()}${path.sep}`);
}
/**
* Ensures the given path exists.
* - If the path already exist, it's fine - it does nothing.
* - If the path doesn't exist, it will create it.
*
* @param {string} path
* @returns {Promise}
*/
function ensureDirectoryExists(dir) {
return stat(dir).catch(() => mkdir(dir, { recursive: true }));
}
/**
* Read a directory,
* sorting folders and files by alphabetically order.
* Can be browsed recursively.
*
* @param {string} dir
* The directory to analyse
*
* @param {boolean} recursive
* Browse directory recursively
*
* @returns {Promise<[string]>}
* All found files, concatenated to the current dir
*/
async function getFilepathsInFolder(dir, recursive = false) {
const pathsList = await readdir(dir);
return flatten(
await Promise.all(
pathsList.sort().map(async (currentPath) => {
const currentFile = path.resolve(dir, currentPath);
const statFile = await stat(currentFile);
if (statFile && statFile.isDirectory()) {
if (recursive) {
return await getFilepathsInFolder(currentFile, true);
}
return [];
}
return [currentFile];
})
)
);
}
module.exports = {
existsSync,
stat,
readdir,
readFile,
writeFile,
createTemp,
ensureDirectoryExists,
getFilepathsInFolder,
};

View File

@ -0,0 +1,12 @@
const isModuleType = require('./is-module-type');
/**
* imports 'mjs', else requires.
* NOTE: require me late!
* @param {string} filepath
*/
module.exports = async function importFile(filepath) {
return (await isModuleType(filepath))
? import(require('url').pathToFileURL(filepath))
: require(filepath);
};

View File

@ -0,0 +1,9 @@
const getPackageType = require('get-package-type');
module.exports = async function isModuleType(filepath) {
return (
filepath.endsWith('.mjs') ||
(!filepath.endsWith('.cjs') &&
(await getPackageType(filepath)) === 'module')
);
};

View File

@ -0,0 +1,52 @@
const template = require('lodash/template');
const { readFile, writeFile } = require('./fs');
/**
* Light wrapper over lodash templates making it safer to be used with javascript source code.
*
* In particular, doesn't interfere with use of interpolated strings in javascript.
*
* @param {string} content Template source
* @param {_.TemplateOptions} options Template options
*/
const jsSourceTemplate = (content, options) =>
template(content, {
interpolate: /<%=([\s\S]+?)%>/g,
...options,
});
/**
* Compile the contents of specified (javascript) file as a lodash template
*
* @param {string} filePath Path of file to be used as template
* @param {_.TemplateOptions} options Lodash template options
*/
const jsFileTemplate = async (filePath, options) => {
const contentBuffer = await readFile(filePath);
return jsSourceTemplate(contentBuffer.toString(), options);
};
/**
* Write a javascript file using another file as a (lodash) template
*
* @param {string} targetFilePath
* @param {string} sourceFilePath
* @param {_.TemplateOptions} options options passed to lodash templates
*/
const writeJsFileUsingTemplate = async (
targetFilePath,
sourceFilePath,
options,
variables
) =>
writeFile(
targetFilePath,
(await jsFileTemplate(sourceFilePath, options))(variables)
);
module.exports = {
jsSourceTemplate,
jsFileTemplate,
writeJsFileUsingTemplate,
};

View File

@ -0,0 +1,14 @@
function yyyymmddhhmmss() {
const now = new Date();
return (
now.getUTCFullYear().toString() +
(now.getUTCMonth() + 1).toString().padStart(2, '0') +
now.getUTCDate().toString().padStart(2, '0') +
now.getUTCHours().toString().padStart(2, '0') +
now.getUTCMinutes().toString().padStart(2, '0') +
now.getUTCSeconds().toString().padStart(2, '0')
);
}
module.exports = { yyyymmddhhmmss };