twenty 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,87 +1,6 @@
1
- # Twenty
1
+ # Twenty CLI
2
2
 
3
- ## What is it?
4
- Twenty is a small package to help you get a location (city/region or lat/lon coordinates) from an IP address. There are also other utilities, like a function that provides a rough distance between two IP addresses. All of this can also be done by specifying the FQDN, like "stackabuse.com" or "google.com".
3
+ The new command-line interface for [Twenty](https://twenty.com) is coming soon.
5
4
 
6
- For location data, the [ipinfo.io](http://ipinfo.io/) REST service is used.
7
-
8
- Twenty was created in conjunction with [this article](http://stackabuse.com/how-to-create-a-node-js-cli-application/).
9
-
10
- ## Installation
11
- Twenty can be installed as a project dependency or global CLI tool:
12
-
13
- ```bash
14
- $ [sudo] npm install twenty [-g]
15
- ```
16
-
17
- ## Usage
18
- There are two ways to use this package: through the command line or by within your code.
19
-
20
- ### Command Line
21
- ```bash
22
- $ twenty [IP | URL] [-d=<IP | URL>] [-ij]
23
- ```
24
-
25
- Twenty takes an optional IP (or URL) address as an argument. If one isn't given, then your own IP address is used. Optionally, a second IP (or URL) address can be given with the `-d` argument to find the distance between the two IP address' locations.
26
-
27
- The `-i` and `-j` flags will print out all of the IP location info in human readable and JSON format, respectively.
28
-
29
- ```bash
30
- $ twenty stackabuse.com -j
31
- {
32
- "ip": "54.173.122.231",
33
- "hostname": "ec2-54-173-122-231.compute-1.amazonaws.com",
34
- "city": "Ashburn",
35
- "region": "Virginia",
36
- "country": "US",
37
- "loc": "39.0437,-77.4875",
38
- "org": "AS14618 Amazon.com, Inc.",
39
- "postal": "20147"
40
- }
41
- ```
42
-
43
- ### In Your Code
44
- Twenty can also be used programmatically. Currently, the functions provided are `info()`, `location()` and `distance()`.
45
-
46
- - `info()`: Provides you with all the IP info as a JavaScript object
47
- - `location()`: Returns the IP's location as a "[CITY], [REGION]" string
48
- - `distance()`: Calculates the distance between two IP addresses in kilometers
49
-
50
- #### Example Code
51
-
52
- ```javascript
53
- var twenty = require('twenty');
54
-
55
- twenty.info('8.8.8.8', function(err, data) {
56
- console.log('Google\'s DNS server is located at:', data.loc);
57
- });
58
-
59
- twenty.location('google-public-dns-a.google.com', function(err, location) {
60
- console.log('Google\'s DNS server is in:', location);
61
- });
62
-
63
- twenty.distance('8.8.8.8', '54.173.122.231', function(err, distance) {
64
- console.log('Distance between Google\'s DNS and stackabuse.com server (km):', distance);
65
- });
66
- ```
67
-
68
- ## Note
69
- Since Twenty uses the ipinfo.io REST service for getting location information, you'll need to be aware of your usage. The daily limit for free usage is 1,000 requests per day. Check the [ipinfo.io](http://ipinfo.io/about) About page for more information.
70
-
71
- ## Why 'Twenty'?
72
- The name 'Twenty' came from the phrase "What's your 20?", which came from the police [10-code](https://en.wikipedia.org/wiki/Ten-code) "10-20", which means "identify your position" or "where are you?".
73
-
74
- ## Copyright & License
75
- Copyright (c) 2015 Scott Robinson
76
-
77
- Permission is hereby granted, free of charge, to any person obtaining a copy
78
- of this software and associated documentation files (the "Software"), to deal
79
- in the Software without restriction, including without limitation the rights
80
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
81
- copies of the Software, and to permit persons to whom the Software is
82
- furnished to do so, subject to the following conditions:
83
-
84
- The above copyright notice and this permission notice shall be included in
85
- all copies or substantial portions of the Software.
86
-
87
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5
+ This package does not provide an executable yet. For the currently available CLI,
6
+ use [twenty-sdk](https://www.npmjs.com/package/twenty-sdk).
package/package.json CHANGED
@@ -1,28 +1,15 @@
1
1
  {
2
2
  "name": "twenty",
3
- "version": "0.1.0",
4
- "description": "Locates the city/region of a given IP address",
5
- "main": "index.js",
3
+ "version": "0.3.0",
4
+ "description": "The new command-line interface for Twenty is coming soon.",
5
+ "homepage": "https://twenty.com",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/scottwrobinson/twentyjs.git"
8
+ "url": "git+https://github.com/twentyhq/twenty.git",
9
+ "directory": "packages/twenty-cli"
9
10
  },
10
- "keywords": [
11
- "cli",
12
- "location",
13
- "ipinfo",
14
- "tools"
15
- ],
16
- "scripts": {
17
- "test": "echo \"Error: no test specified\" && exit 1"
11
+ "bugs": {
12
+ "url": "https://github.com/twentyhq/twenty/issues"
18
13
  },
19
- "author": "Scott Robinson <s.w.robinson@gmail.com> (http://stackabuse.com)",
20
- "license": "MIT",
21
- "dependencies": {
22
- "request": "^2.67.0",
23
- "yargs": "^3.31.0"
24
- },
25
- "bin": {
26
- "twenty": "./bin/twenty"
27
- }
28
- }
14
+ "license": "AGPL-3.0"
15
+ }
package/.npmignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules/
2
- todo.txt
package/bin/twenty DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- require('../index').cli();
package/index.js DELETED
@@ -1,104 +0,0 @@
1
- var dns = require('dns');
2
- var request = require('request');
3
-
4
- var ipRegex = /(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/;
5
-
6
- var toRad = function(num) {
7
- return num * (Math.PI / 180);
8
- };
9
-
10
- var getIpInfo = function(server, callback) {
11
- var ipinfo = function(p, cb) {
12
- request('http://ipinfo.io/' + p, function(err, response, body) {
13
- var json = JSON.parse(body);
14
- cb(err, json);
15
- });
16
- };
17
-
18
- if (!server) {
19
- return ipinfo('json', callback);
20
- } else if (!server.match(ipRegex)) {
21
- return dns.lookup(server, function(err, data) {
22
- ipinfo(data, callback);
23
- });
24
- } else {
25
- return ipinfo(server, callback);
26
- }
27
- };
28
-
29
- var ipDistance = function(lat1, lon1, lat2, lon2) {
30
- // Earth radius in km
31
- var r = 6371;
32
-
33
- var dLat = toRad(lat2 - lat1);
34
- var dLon = toRad(lon2 - lon1);
35
- lat1 = toRad(lat1);
36
- lat2 = toRad(lat2);
37
-
38
- var a = Math.sin(dLat / 2.0) * Math.sin(dLat / 2.0) +
39
- Math.sin(dLon / 2.0) * Math.sin(dLon / 2.0) * Math.cos(lat1) * Math.cos(lat2);
40
- var c = 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0 - a));
41
- return r * c;
42
- };
43
-
44
- var findLocation = function(server, callback) {
45
- getIpInfo(server, function(err, data) {
46
- callback(null, data.city + ', ' + data.region);
47
- });
48
- };
49
-
50
- var findDistance = function(ip1, ip2, callback) {
51
- var lat1, lon1, lat2, lon2;
52
-
53
- getIpInfo(ip1, function(err, data1) {
54
- var coords1 = data1.loc.split(',');
55
- lat1 = Number(coords1[0]);
56
- lon1 = Number(coords1[1]);
57
- getIpInfo(ip2, function(err, data2) {
58
- var coords2 = data2.loc.split(',');
59
- lat2 = Number(coords2[0]);
60
- lon2 = Number(coords2[1]);
61
-
62
- var dist = ipDistance(lat1, lon1, lat2, lon2);
63
- callback(null, dist);
64
- });
65
- });
66
- };
67
-
68
- var cli = function() {
69
- var argv = require('yargs')
70
- .alias('d', 'distance')
71
- .alias('j', 'json')
72
- .alias('i', 'info')
73
- .argv;
74
-
75
- if (argv.d) {
76
- findDistance(argv._[0], argv.d, function(err, distance) {
77
- console.log(distance);
78
- });
79
- } else if (argv.j) {
80
- getIpInfo(argv._[0], function(err, data) {
81
- console.log(JSON.stringify(data, null, 4));
82
- });
83
- } else if (argv.i) {
84
- getIpInfo(argv._[0], function(err, data) {
85
- console.log('IP:', data.ip);
86
- console.log('Hostname:', data.hostname);
87
- console.log('City:', data.city);
88
- console.log('Region:', data.region);
89
- console.log('Postal:', data.postal);
90
- console.log('Country:', data.country);
91
- console.log('Coordinates:', data.loc);
92
- console.log('ISP:', data.org);
93
- });
94
- } else {
95
- findLocation(argv._[0], function(err, location) {
96
- console.log(location);
97
- });
98
- }
99
- };
100
-
101
- exports.info = getIpInfo;
102
- exports.location = findLocation;
103
- exports.distance = findDistance;
104
- exports.cli = cli;