How to use ini - 10 common examples

To help you get started, we’ve selected a few ini examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github balena-io-projects / boombeastic / app / index.js View on Github external
// Google Play Music config
  mopidy.gmusic.enabled = process.env.MOPIDY_GMUSIC_ENABLED === '1' ? true : false;
  mopidy.gmusic.username = process.env.MOPIDY_GMUSIC_USERNAME || "none";
  mopidy.gmusic.password = process.env.MOPIDY_GMUSIC_PASSWORD || "none";
  mopidy.gmusic.all_access = process.env.MOPIDY_GMUSIC_ALL_ACCESS === '1' ? true : false;
  // Spotify config
  mopidy.spotify.enabled = process.env.MOPIDY_SPOTIFY_ENABLED === '1' ? true : false;
  mopidy.spotify.username = process.env.MOPIDY_SPOTIFY_USERNAME || "none";
  mopidy.spotify.password = process.env.MOPIDY_SPOTIFY_PASSWORD || "none";
  // Soundcloud config
  mopidy.soundcloud.enabled = process.env.MOPIDY_SOUNDCLOUD_ENABLED === '1' ? true : false;
  mopidy.soundcloud.auth_token = process.env.MOPIDY_SOUNDCLOUD_AUTH_TOKEN || "none";
  // YouTube config
  mopidy.youtube.enabled = process.env.MOPIDY_YOUTUBE_ENABLED === '1' ? true : false;

  fs.writeFileSync('/etc/mopidy/mopidy.conf', ini.stringify(mopidy));
  fs.writeFileSync('/etc/shairport-sync.conf', 'general =\n{\nname = "BoomBeastic-' + process.env.RESIN_DEVICE_UUID.substring(0, 7) + '";\n};');

  // Mopidy
  console.log(chalk.cyan('starting Mopidy - HTTP port:' + mopidy.http.port + ' (proxy on port 80); MPD port:' + mopidy.mpd.port));
  display.init(() => {
    'use strict';
    display.image(display.presets.splash);
  });
  exec('systemctl start mopidy', (error, stdout, stderr) => {
    'use strict';
    if (error) {
      console.log(chalk.red(`exec error: ${error}`));
      return;
    }
  });
github jonschlinkert / data-store / examples / ini.js View on Github external
function readParseFile() {
  let data;
  
  console.log('readParseFile');
  try {
    data = fs.readFileSync(this.path, 'utf-8');
  } catch (e) {
    console.log('readParseFile error; starting with empty data');
    data = {};
  }

  // Parse the INI-format configuration file
  return ini.parse(data);
}
github Tarnadas / smmdb / website / src / server / scripts / api.ts View on Github external
public static async getCourses (app: any, req: any, res: any, apiData: any): Promise {
    const auth = req.get('Authorization')
    const apiKey = auth != null && auth.includes('APIKEY ') && auth.split('APIKEY ')[1]
    const account = await Account.getAccountByAPIKey(apiKey)
    if (apiData.prettify) {
      app.set('json spaces', 2)
    }
    const courses = await this.filterCourses(account ? account._id : null, apiData)
    if (apiData.format === 'ini') {
      res.set('Content-type', 'text/plain')
      res.send(`${encode({ General: { lvlcount: courses.length } })}\n${encode(JSON.parse(JSON.stringify(courses)), {
        section: 'Level',
        whitespace: false // TODO
      })}`)
    } else {
      res.json(courses)
    }
    if (apiData.prettify) {
      app.set('json spaces', 0)
    }
  }
github sidneys / ffmpeg-progressbar-cli / lib / main.js View on Github external
let onData = (data) => {
        if (!didStart) {
            // Bar::start()
            bar.start(totalTimeMs, {
                filename: formatter.filepathToFilename(filePath, BAR_FILENAME_LENGTH)
            })
            didStart = true
        }

        // Parse sparse output of nearly undocumented `-progress` argument 🤬🤬🤬
        // That is, key-value-pairs in .ini format
        const progressDictionary = ini.decode(data.toString())

        const currentTimeMicroseconds = Number(progressDictionary['out_time_ms'])
        const currentTimeMs = Math.round(currentTimeMicroseconds / 1000)

        // Bar::update() (noncritical errors are written to Bar.annotation)
        bar.update(currentTimeMs, null, !!lastError ? theme.warning(ellipsize(lastError, progressbarWidth + 7)) : null)

        // DEBUG
        // console.debug('progress (ms)', progressMilliseconds, 'duration (ms)', durationMilliseconds, 'fraction', (progressMilliseconds / durationMilliseconds))
    }
github dimitrov-adrian / RcloneTray / src / rclone.js View on Github external
}
    } else {
      // Sanitize booleans.
      if (optionDefinition.$Type === 'boolean') {
        if (optionDefinition.Name in values && ['true', 'yes', true, 1].indexOf(values[optionDefinition.Name]) > -1) {
          values[optionDefinition.Name] = 'true'
        } else {
          values[optionDefinition.Name] = 'false'
        }
      }
      valuesPlain[optionDefinition.Name] = values[optionDefinition.Name]
    }
  })

  try {
    let configIniStruct = ini.decode(fs.readFileSync(getConfigFile()).toString())
    configIniStruct[bookmarkName] = Object.assign(configIniStruct[bookmarkName], valuesPlain)
    fs.writeFileSync(getConfigFile(), ini.encode(configIniStruct, {
      whitespace: true
    }))
  } catch (err) {
    console.error(err)
    throw Error('Cannot update bookmark fields.')
  }
  console.log('Rclone', 'Updated bookmark', bookmarkName)
}
github TencentCloudBase / cloudbase-cli / src / utils.ts View on Github external
export async function getMetadata() {
    if (fs.existsSync(TCBRC)) {
        const tcbrc = ini.parse(fs.readFileSync(TCBRC, 'utf-8'))
        if (!tcbrc.secretId || !tcbrc.secretKey || !tcbrc.host || !tcbrc.password || !tcbrc.username || !tcbrc.port) {
            // 缺少信息,重新登录
            return await login()
        }
        return tcbrc
    } else {
        // 没有登录过
        return await login()
    }
}
github SSilence / sum / app / sum-init.js View on Github external
$(document).ready(function() {
    
    // read config
    
    // get default config
    config = ini.parse(fs.readFileSync('./app/default.ini', 'utf-8'));

    // helper returns true if file exists, false otherwise
    var fileExists = function(filename) {
        try {
            fs.accessSync(filename);
        } catch(e) {
            return false;
        }
        return true;
    };
    
    // for linux or osx overwrite values from ~/.sum.ini configuration file
    if (os.platform() == 'linux' || os.platform() == 'darwin')
        if (fileExists(process.env.HOME + '/.sum.ini'))
            $.extend(config, ini.parse(fs.readFileSync(process.env.HOME + '/.sum.ini', 'utf-8')));
github TencentCloudBase / cloudbase-cli / lib / utils.js View on Github external
}
    // 存在临时密钥信息
    if (tcbrc.refreshToken) {
        // 临时密钥在 2 小时有效期内,可以直接使用
        if (Date.now() < tcbrc.tmpExpired) {
            const { tmpSecretId, tmpSecretKey, tmpToken } = tcbrc;
            return {
                secretId: tmpSecretId,
                secretKey: tmpSecretKey,
                token: tmpToken
            };
        }
        else if (Date.now() < tcbrc.expired) {
            // 临时密钥超过两小时有效期,但在 1 个月 refresh 有效期内,刷新临时密钥
            const credential = await auth_1.refreshTmpToken(tcbrc);
            fs.writeFileSync(constant_1.TCBRC, ini.stringify(credential));
            const { tmpSecretId, tmpSecretKey, tmpToken } = credential;
            return {
                secretId: tmpSecretId,
                secretKey: tmpSecretKey,
                token: tmpToken
            };
        }
    }
    // 无有效身份信息,提示登录
    logger.error('无有效身份信息,请使用 tcb login 登录');
    return {};
}
exports.getMetadata = getMetadata;
github mozilla / dxr / tooling / node / node_modules / lockdown / node_modules / npmconf / npmconf.js View on Github external
var data = target.data

  if (typeof data._password === 'string' &&
      typeof data.username === 'string') {
    var auth = data.username + ':' + data._password
    data = Object.keys(data).reduce(function (c, k) {
      if (k === 'username' || k === '_password')
        return c
      c[k] = data[k]
      return c
    }, { _auth: new Buffer(auth, 'utf8').toString('base64') })
    delete data.username
    delete data._password
  }

  data = ini.stringify(data)

  then = then.bind(this)
  done = done.bind(this)
  this._saving ++

  var mode = where === 'user' ? 0600 : 0666
  if (!data.trim()) {
    fs.unlink(target.path, function (er) {
      // ignore the possible error (e.g. the file doesn't exist)
      done(null)
    })
  } else {
    mkdirp(path.dirname(target.path), function (er) {
      if (er)
        return then(er)
      fs.writeFile(target.path, data, 'utf8', function (er) {
github geeklearningio / gl-vsts-tasks-yarn / Tasks / Yarn / npmrcparser.ts View on Github external
export function GetRegistries(npmrc: string): string[] {
    let registries: string[] = [];
    let config = ini.parse(fs.readFileSync(npmrc).toString());

    for (let key in config) {
        let colonIndex = key.indexOf(":");
        if (key.substring(colonIndex + 1).toLowerCase() === "registry") {
            config[key] = NormalizeRegistry(config[key]);
            registries.push(config[key]);
        }
    }

    // save the .npmrc with normalized registries
    tl.writeFile(npmrc, ini.stringify(config));
    return registries;
}

ini

An ini encoder/decoder for node

ISC
Latest version published 2 months ago

Package Health Score

95 / 100
Full package analysis