How to use the hostile.get function in hostile

To help you get started, we’ve selected a few hostile 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 bbeldame / local.dev / index.js View on Github external
return new Promise((resolve) => {
    let ip = '';

    function filterFunc(line) {
      return !((Array.isArray(line) && line[1] === url) || (typeof line === 'string' && line.split(' ')[2] === this.port));
    }

    function hostileRemove(lines, port) {
      // Try to remove entry, if it exists
      const filteredLines = lines.filter(filterFunc, { port });
      return hostile.writeFile(filteredLines, () => {
        resolve(ip);
      });
    }

    hostile.get(true, (err, lines) => {
      if (err) error(err);
      let port = '';
      for (let i = 0; i < lines.length; i += 1) {
        if (typeof lines[i] === 'object' && lines[i][1] === url) {
          port = lines[i - 1].split(' ')[2];
          ip = lines[i][0];
        }
      }
      if (port === '') {
        error('This local.dev is not found');
      }
      return hostileRemove(lines, port);
    });
  });
}
github bbeldame / local.dev / index.js View on Github external
exports.list = function list() {
  hostile.get(true, (err, lines) => {
    if (err) {
      error(err);
    }

    for (let i = 0; i < lines.length; i += 1) {
      if (lines[i].slice(0, 11) === '# local.dev') {
        const port = lines[i].split(' ')[2];
        const url = lines[i + 1][1];
        console.log(`localhost:${chalk.green(`${port} <-`)} ${chalk.green(url)}`);
        i += 1;
      }
    }
  });
};
github leftstick / hosts-high / src / helpers / hostsControl.js View on Github external
return new Promise(function(resolve, reject) {
    hostile.get(false, function(error, lines) {
      if (error) {
        return reject(error.message)
      }
      const rowData = lines.map(line => {
        const ip = line[0]
        const domain = line[1]
        return {
          alias: localStorage.getItem(ALIAS_PREFIX + ip + domain),
          disabled: false,
          domain: domain,
          ip: ip
        }
      })
      const hosts = rowData.concat(disabledList)
      hosts.sort(function(a, b) {
        const aa = a.ip.split('.')
github leftstick / hosts-high / src / renderer / stores / useHostsModel.js View on Github external
return new Promise((resolve, reject) => {
        hostile.get(false, (err, lines) => {
          const isDefined = lines.some(line => line[0] === host.ip && line[1] === host.domain)
          if (isDefined) {
            return reject(`host [${host.ip} ${host.domain}] has been used`)
          }

          hostile.set(host.ip, host.domain, err => {
            if (err) {
              return reject(`Failed to add [${host.ip} ${host.domain}]: ${err.message}`)
            }
            if (host.alias) {
              setAliases({ ...aliases, [host.ip + host.domain]: host.alias })
            }
            setSysHosts(sysHosts => [...sysHosts, { ...host, disabled: false, alias: aliases[host.ip + host.domain] }])
            resolve()
          })
        })

hostile

Simple /etc/hosts manipulation

MIT
Latest version published 4 months ago

Package Health Score

72 / 100
Full package analysis