Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
umask.js36 linesDownload Raw Back to lib
1const parse = val => {
2  // this is run via nopt and parse field where everything is
3  // converted to a string first, ignoring coverage for now
4  // instead of figuring out what is happening under the hood in nopt
5  // istanbul ignore else
6  if (typeof val === 'string') {
7    if (/^0o?[0-7]+$/.test(val)) {
8      return parseInt(val.replace(/^0o?/, ''), 8)
9    } else if (/^[1-9][0-9]*$/.test(val)) {
10      return parseInt(val, 10)
11    } else {
12      throw new Error(`invalid umask value: ${val}`)
13    }
14  } else {
15    if (typeof val !== 'number') {
16      throw new Error(`invalid umask value: ${val}`)
17    }
18    val = Math.floor(val)
19    if (val < 0 || val > 511) {
20      throw new Error(`invalid umask value: ${val}`)
21    }
22    return val
23  }
24}
25
26const validate = (data, k, val) => {
27  try {
28    data[k] = parse(val)
29    return true
30  } catch (er) {
31    return false
32  }
33}
34
35module.exports = { parse, validate }
36 
codekingpro/portable-devtools · Team Ai