Hostify
Hostify is a module that help us to work with the hosts
file of our operating system.
It supports both a CLI tool and a module you can use in your own project.
NOTE: library in progress. Please use with caution and report any issue on here: https://github.com/eridem/hostify/issues
CLI tool operations
# Usage hostify [COMMAND] [OPTIONS] # For help hostify --helphostify [COMMAND] --help
Command | Description | Example |
---|---|---|
list |
Show all entries in the host file | hostify list |
list --ipFilterExp "REGEXP" |
Show entries which IPs match with RegExp | hostify list --ipFilterExp ".*\.255" |
list --hostFilterExp "REGEXP" |
Show entries which Host match with RegExp | hostify list --hostFilterExp ".*tracking.*" |
list --ipFilterExp "REGEXP" --hostFilterExp "REGEXP" |
Show entries which IP and Host match with both each RegExp | hostify list --ipFilterExp "0.0.0.0" --hostFilterExp ".*tracking.*" |
add --ip "IP" --host "HOST" [--comment "COMMENT"] |
Add a single entry to the hosts file |
hostify add --ip "0.0.0.0" --host "tracking.localhost" --comment "Tracking entry" |
delete --ipFilterExp "REGEXP" [--what-if] |
Delete entries which IPs match with RegExp | hostify delete --ipFilterExp "127.0.0.\d+" |
delete --hostFilterExp "REGEXP" [--what-if] |
Delete entries which Host match with RegExp | hostify delete --hostFilterExp ".*project\.local" |
Special options
Option | Description | Example |
---|---|---|
--path |
Specify path of another hosts file |
hostify list --path ./my-hosts.txt |
Module interface
Import module with:
const hostify = operations
List
hostify.listoptions: Array`
Show entries in the host file.
Option | Model | Default |
---|---|---|
filterIpFn |
filterIpFn: (val: string) => boolean |
(v) => true |
filterHostFn |
filterHostFn: (val: string) => boolean |
(v) => true |
path |
path: string |
OS hosts path |
const options = val // Filter IPs val // Filter Hosts // path: './my-hosts-file.txt' // Hosts file const entries = hostify entries
Add
hostify.addoptions: Array
Add entries in the host file.
Option | Model | Default |
---|---|---|
entries |
<Array>{ ip: string, host: string, comment: string } |
null |
path |
path: string |
OS hosts path |
const options = entries: // Entries to add ip: '0.0.0.0' host: 'ad.localhost' ip: '0.0.0.0' host: 'tracking.localhost' comment: 'Track entry' // path: './my-hosts-file.txt' // Hosts file const entries = hostify entries
Delete
hostify.deleteoptions: Array
Delete entries in the host file.
Option | Model | Default |
---|---|---|
filterIpFn |
filterIpFn: (val: string) => boolean |
(v) => true |
filterHostFn |
filterHostFn: (val: string) => boolean |
(v) => true |
whatIf |
whatIf: boolean |
false |
path |
path: string |
OS hosts path |
const options = val // Filter IPs val // Filter Hosts whatIf: true // Do not execute delete operation, only obtain results // path: './my-hosts-file.txt' // Hosts file const entries = hostify entries