/
format.js
executable file
·33 lines (28 loc) · 925 Bytes
/
format.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const semver = require('semver');
/**
* Determines whether or not the string is lowercase
* @param {string} name Name
* @return {boolean} True if the string is lowercase or is missing. False if it is not.
*/
const isLowercase = name => {
if (typeof name !== 'string') {
return true;
}
return name === name.toLowerCase();
};
/**
* Determines whether or not the node's value is a valid semantic version
* @param {object} packageJsonData Valid JSON
* @param {string} nodeName Name of a node in the package.json file
* @return {boolean} True if the node is a valid version number or is missing. False if it is not.
*/
const isValidVersionNumber = (packageJsonData, nodeName) => {
if (!packageJsonData.hasOwnProperty(nodeName)) {
return true;
}
return semver.valid(packageJsonData[nodeName]) !== null;
};
module.exports = {
isLowercase,
isValidVersionNumber
};