Skip to content

Commit

Permalink
rewrite:move to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
mondyfy committed Aug 17, 2023
1 parent 0b4e89f commit d8548de
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 23 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
# loc-bind
# GeoEnclave

June. 15, 2020
August. 18, 2023
<br />

Ever had the urge to validate location on region based services? And wanted to validate geolocation in some sane and easy way? Don't want to use third party APIs', for whatever reason? Then loc-bind is what you're looking for!
"GeoEnclave" essentially means a defined and secured geographical space where specific rules or validations can be applied.

## Description

loc-bind is a tiny npm package that takes the bounded area in th form of polygon coordinates and checks if the point/location lat, long lies inside the bounded region or not.
> Meet GeoEnclave, the game-changing npm package for effortless geolocation validation! 🌐🔍
Say farewell to third-party APIs and hello to simplicity. With loc-bind, you're the boss. Define your bounded area using polygon coordinates, and let loc-bind work its magic. It checks if a point's latitude and longitude lie within your defined region. Your location, your rules – all in a tiny, powerful package. 📦📍 #OwnYourGeo

## Install

```
$ npm i loc-bind
$ npm i geoenclave
or
$ yarn add loc-bind
$ yarn add geoenclave
```

## Usage

```javascript
const locBind = require('loc-bind');
// Load core loc-bind.
const geoEnclave = require('geoenclave');
// Load core geoenclave.

const polygonCoordinates = [
[85.27268661724837, 27.703490979573274],
Expand Down Expand Up @@ -58,10 +60,10 @@ in Geopackage .gpkg format */
const coordThamel = [85.3061304421, 27.709090497];
const coordCharikot = [86.0333332, 27.666664];

console.log(locBind.inside(coordThamel, polygonCoordinates));
console.log(geoEnclave.inside(coordThamel, polygonCoordinates));
// returns true as thamel lies inside kathmandu valley

console.log(locBind.inside(coordCharikot, polygonCoordinates));
console.log(geoEnclave.inside(coordCharikot, polygonCoordinates));
// returns false as charikot doesn't lie inside kathmandu valley

```
Expand All @@ -77,3 +79,6 @@ Any kinds of contributions are entertained.
[Point In Polygon](https://github.com/substack/point-in-polygon)

[Robust Point In Polygon](https://github.com/mikolalysenko/robust-point-in-polygon)

## License
[MIT](LICENSE)
12 changes: 6 additions & 6 deletions index.js → index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
inside = (point, polygon) => {
const inside = (point: [number, number], polygon: [number, number][]): boolean => {
const x = point[0], y = point[1];

let inside = false;
let isInside = false;
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
const xi = polygon[i][0], yi = polygon[i][1];
const xj = polygon[j][0], yj = polygon[j][1];

const intersect = ((yi > y) != (yj > y))
const isIntersect = ((yi > y) !== (yj > y))
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
if (intersect) inside = !inside;
if (isIntersect) isInside = !isInside;
}
return inside;
return isInside;
};

module.exports = { inside };
export { inside };
22 changes: 15 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
{
"name": "loc-bind",
"version": "1.0.6",
"description": "Package that takes lat long array and validates geocoordinates if that lies inside it.",
"main": "index.js",
"name": "geoenclave",
"version": "2.0.0",
"description": "Validate if a point is inside a given polygon using GeoEnclave.",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"loc-bind",
"location-binder",
"geoenclave",
"geocoordinate",
"validation",
"location security",
"npm package",
"location-validation"
],
"author": "Sandip Basnet",
"repository": {
"type": "git",
"url": "git+https://github.com/mondyfy/loc-bind"
"url": "git+https://github.com/mondyfy/geoenclave"
},
"dependencies": {},
"devDependencies": {
"typescript": "^5.1.6"
},
"license": "MIT"
}
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES6",
"module": "CommonJS",
"outDir": "./dist",
"strict": true,
"esModuleInterop": true
},
"exclude": [
"node_modules",
"dist"
]
}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


typescript@^4.4.3:
version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

0 comments on commit d8548de

Please sign in to comment.