Comparing version 0.3.0 to 0.4.0
import type { Location } from "geonumber"; | ||
export { Location }; | ||
import { bip39, dictionaries } from "./words/index.js"; | ||
export { bip39, dictionaries }; | ||
export declare function countDictionaryBits(dict: string[]): bigint; | ||
export declare function prepareDictionaryFromText(text: string): string[]; | ||
export declare function encodeNumber(number: bigint, wordsCount?: number, dict?: string[]): string[]; | ||
@@ -4,0 +8,0 @@ export declare function decodeNumber(inputWords: string[], dict?: string[]): bigint; |
@@ -1,3 +0,8 @@ | ||
import english from "./english"; | ||
export { english }; | ||
export default english; | ||
import bip39 from "./bip39.js"; | ||
import doi from "./doi.js"; | ||
export { bip39, doi }; | ||
export declare const dictionaries: { | ||
bip39: string[]; | ||
doi: string[]; | ||
}; | ||
export default bip39; |
{ | ||
"name": "geowords", | ||
"version": "0.3.0", | ||
"description": "Library for encoding geographic coordinates as sequence of words from bip39 set", | ||
"version": "0.4.0", | ||
"description": "Tool for encoding geographic coordinates as sequence of words from bip39 or other dictionary", | ||
"repository": { | ||
@@ -10,9 +10,13 @@ "type": "git", | ||
}, | ||
"bin": { | ||
"geowords": "./bin/geowords.js" | ||
}, | ||
"type": "module", | ||
"main": "lib/index.mjs", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"scripts": { | ||
"test": "tape tests/*", | ||
"build": "rimraf ./lib; tsc --build && renamer --find '/\\.js/i' --replace '.mjs' './lib/**/*'", | ||
"test": "npm run build; tape tests/*", | ||
"build": "rimraf ./lib; tsc --build", | ||
"clean": "tsc --build --clean", | ||
"docs": "typedoc --plugin typedoc-plugin-markdown src/index.ts --githubPages false --readme none --theme markdown && concat-md --dir-name-as-title docs > docs.md && rimraf docs", | ||
"prepare": "npm run build" | ||
@@ -40,2 +44,3 @@ }, | ||
"devDependencies": { | ||
"concat-md": "^0.5.0", | ||
"renamer": "^4.0.0", | ||
@@ -45,5 +50,8 @@ "rimraf": "^3.0.2", | ||
"tsc": "^2.0.4", | ||
"typescript": "^4.8.4" | ||
"typedoc": "^0.23.15", | ||
"typedoc-plugin-markdown": "^3.13.6", | ||
"typescript": "^4.8.4", | ||
"yargs": "^17.2.1" | ||
}, | ||
"gitHead": "45e65ed66878ac523758052148d78771bb90f28d" | ||
"gitHead": "1f58f1b91a0ee1a6af3c89f2b8ff244102db3202" | ||
} |
@@ -7,9 +7,69 @@ # Welcome to geowords 👋 | ||
> Library for encoding geographic coordinates as sequence of words from bip39 set | ||
> Tool for encoding geographic coordinates as sequence of words from bip39 or other dictionary | ||
### 🏠 [Homepage](https://github.com/MLaszczewski/geowords) | ||
# Command line interface | ||
## Install | ||
```sh | ||
yarn global add geowords | ||
``` | ||
or | ||
```sh | ||
npm install --global geowords | ||
``` | ||
## Usage | ||
``` | ||
> geowords encode 23 23 4 | ||
ship add travel abstract | ||
> geowords decode ship add travel | ||
22.9998779296875 22.9998779296875 | ||
> geowords decode ship add | ||
22.939453125 22.8515625 | ||
``` | ||
### Encode or decode geographic coordinates: | ||
``` | ||
geowords encode [lat] [lon] [words] [options] | ||
lat latitude [required] | ||
lon longitude [required] | ||
words number of words [default: 4] | ||
``` | ||
``` | ||
geowords.js decode [words...] | ||
words coordinates encoded as words [required] | ||
``` | ||
#### Options: | ||
``` | ||
--dict select embedded dictionary ( bip39 | doi ) | ||
[default: "bip39"] | ||
--dictFile load dictionary from file [string] | ||
``` | ||
### Generate dictionary | ||
``` | ||
geowords.js dictionary [sourceFile] [dictFile] | ||
sourceFile file containing text to create dictionary from [required] | ||
dictFile file to save dictionary to [required] | ||
``` | ||
#### Options: | ||
``` | ||
--help Show help [boolean] | ||
--version Show version number [boolean] | ||
--minWordLength minimum word length [default: 3] | ||
--maxWordLength maximum word length [default: 10] | ||
--maxLength maximum dictionary length [default: 4096] | ||
--format output format ( list | json | esm )[string] [default: "list"] | ||
``` | ||
# Package | ||
### 📄 [API Documentation](https://github.com/MLaszczewski/geowords/blob/master/packages/geowords/docs.md) | ||
## Install package | ||
```sh | ||
yarn add geowords | ||
@@ -16,0 +76,0 @@ ``` |
@@ -1,10 +0,28 @@ | ||
import words from "./words/index" | ||
import words from "./words/index.js" | ||
import * as geonumber from "geonumber" | ||
import type { Location } from "geonumber" | ||
export { Location } | ||
const wordBits = 11n | ||
import { bip39, dictionaries } from "./words/index.js"; | ||
export { bip39, dictionaries } | ||
export function countDictionaryBits(dict: string[]):bigint { | ||
return BigInt(BigInt(dict.length).toString(2).length - 1) | ||
} | ||
export function prepareDictionaryFromText(text: string):string[] { | ||
const dict = text.split(/[^\w]/).filter(x => x.length > 0).map(w => w.toLowerCase()) | ||
for(let i = 0; i < dict.length; i++) { | ||
for(let j = i + 1; j < dict.length; j++) { | ||
if(dict[i] === dict[j]) { | ||
dict.splice(j, 1) | ||
j-- | ||
} | ||
} | ||
} | ||
return dict | ||
} | ||
export function encodeNumber(number: bigint, wordsCount: number = 3, dict: string[] = words): string[] { | ||
const wordBits = countDictionaryBits(dict) | ||
const words = new Array(wordsCount) | ||
@@ -21,2 +39,3 @@ let rest = number | ||
export function decodeNumber(inputWords: string[], dict: string[] = words): bigint { | ||
const wordBits = countDictionaryBits(dict) | ||
let acc = 0n | ||
@@ -33,2 +52,3 @@ for(let wordIndex = 0; wordIndex < inputWords.length; wordIndex++) { | ||
dict: string[] = words): string[] { | ||
const wordBits = countDictionaryBits(dict) | ||
const bits = BigInt(wordsCount) * wordBits | ||
@@ -40,2 +60,3 @@ const number = geonumber.encodeLocation({ lat, lon }, bits) | ||
export function decodeLocation(inputWords: string[], dict: string[] = words): Location { | ||
const wordBits = countDictionaryBits(dict) | ||
const bits = BigInt(inputWords.length) * wordBits | ||
@@ -42,0 +63,0 @@ const number = decodeNumber(inputWords, dict) |
@@ -1,7 +0,10 @@ | ||
import english from "./english" | ||
import bip39 from "./bip39.js" | ||
import doi from "./doi.js" | ||
export { | ||
english | ||
bip39, | ||
doi | ||
} | ||
export default english | ||
export const dictionaries = { bip39, doi } | ||
export default bip39 |
@@ -9,4 +9,4 @@ { | ||
"module": "ES2020", | ||
"moduleResolution": "node", | ||
"lib": ["es2020"], | ||
"moduleResolution": "nodenext", | ||
"lib": ["es2020", "dom"], | ||
"allowSyntheticDefaultImports": true, | ||
@@ -13,0 +13,0 @@ "declaration": true |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
112334
25
4937
114
9
1