🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

quadbin

Package Overview
Dependencies
Maintainers
16
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quadbin - npm Package Compare versions

Comparing version

to
0.4.0-alpha.0

dist/index.cjs

19

CONTRIBUTING.md

@@ -0,1 +1,10 @@

# Contributing
_Contributions are subject to CARTO's [community contributions policy](https://carto.com/contributions/)._
## Local development requirements
- Yarn v4+
- Node.js v18+
## Quickstart

@@ -22,4 +31,10 @@

1. Create a new version: `yarn version [ major | minor | patch | prerelease ]`
1. Update changelog
2. Execute `yarn publish`
2. Create a new version: `yarn version [ major | minor | patch | prerelease ]`
3. Commit, tag, and push to GitHub: `yarn postversion`
4. Publish
- If working on `master`, the previous step will automatically create and push a branch. Open a pull request, get any required approvals, and merge. Merged pull requests with commit messages beginning `chore(release)` will trigger a release automatically.
- If working on a branch, a commit for the release will be pushed to the branch. You'll then need to [manually run a workflow](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow), “Release”, selecting the target branch in the menu.

70

package.json
{
"name": "quadbin",
"version": "0.3.0",
"version": "0.4.0-alpha.0",
"description": "Utility functions for working with Quadbins",
"license": "MIT",
"type": "module",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"umd:main": "dist/umd/index.js",
"types": "dist/types/index.d.ts",
"source": "./src/index.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.esm.js",
"umd:main": "./dist/index.umd.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.cjs"
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs"
},

@@ -29,12 +30,14 @@ "./*": "./*"

"scripts": {
"clean": "rm -rf dist/*",
"build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types && yarn build:umd",
"build:cjs": "tsc -p tsconfig/tsconfig.cjs.json && mv dist/cjs/index.js dist/cjs/index.cjs",
"build:esm": "tsc -p tsconfig/tsconfig.esm.json",
"build:types": "tsc -p tsconfig/tsconfig.types.json",
"build:umd": "webpack --config tsconfig/webpack.config.cjs",
"clean": "rm -rf \"dist/*\"",
"build": "microbundle --name quadbin --format cjs,modern,umd --no-compress",
"build:watch": "microbundle watch --name quadbin --format cjs,modern,umd --no-compress",
"lint": "prettier --check src",
"test": "yarn lint && yarn test-fast",
"test-fast": "ts-node node_modules/tape/bin/tape test/**/*.spec.js",
"prepublishOnly": "yarn build"
"test-fast": "tsx node_modules/tape/bin/tape test/**/*.spec.js",
"postversion": "yarn postversion:check && yarn postversion:commit && yarn postversion:push",
"postversion:check": "yarn lint && yarn test",
"postversion:commit": "node scripts/postversion-commit.js",
"postversion:push": "git push && git push --tags",
"prepublish": "yarn lint && yarn test",
"prepack": "yarn clean && yarn build"
},

@@ -45,17 +48,19 @@ "browser": {

"devDependencies": {
"@babel/register": "^7.13.0",
"@types/geojson": "^7946.0.14",
"babel-loader": "^8.0.0",
"babel-preset-minify": "^0.5.0",
"prettier": "^2.4.1",
"@types/geojson": "^7946.0.15",
"@types/semver": "^7",
"microbundle": "^0.15.1",
"prettier": "^3.4.2",
"semver": "^7.6.3",
"tape": "^5.3.0",
"ts-loader": "^9.2.5",
"ts-node": "^10.9.2",
"typescript": "^4.4.4",
"webpack": "^5.52.1",
"webpack-cli": "^4.8.0"
"tsx": "^4.19.2",
"typescript": "^5.7.3"
},
"engines": {
"node": ">=14"
"node": ">=18"
},
"browserslist": [
"defaults",
"not IE 11",
"node >= 18"
],
"dependencies": {

@@ -65,7 +70,8 @@ "@mapbox/tile-cover": "3.0.1",

},
"packageManager": "yarn@1.22.22",
"packageManager": "yarn@4.3.1",
"volta": {
"node": "14.21.3",
"yarn": "1.22.22"
}
}
"node": "20.18.2",
"yarn": "4.3.1"
},
"stableVersion": "0.3.0"
}

@@ -110,2 +110,28 @@ import {tiles} from '@mapbox/tile-cover';

/**
* Returns the children of a cell, in row-major order starting from NW and ending at SE.
*/
export function cellToChildren(quadbin: Quadbin, resolution: bigint): Quadbin[] {
if (resolution < 0 || resolution > 26 || resolution < getResolution(quadbin)) {
throw new Error('Invalid resolution');
}
const zoomLevelMask = ~(0x1fn << 52n);
const blockRange = 1n << ((resolution - ((quadbin >> 52n) & 0x1fn)) << 1n);
const sqrtBlockRange = 1n << (resolution - ((quadbin >> 52n) & 0x1fn));
const blockShift = 52n - (resolution << 1n);
const childBase =
((quadbin & zoomLevelMask) | (resolution << 52n)) & ~((blockRange - 1n) << blockShift);
const children: Quadbin[] = [];
for (let blockRow = 0n; blockRow < sqrtBlockRange; blockRow++) {
for (let blockColumn = 0n; blockColumn < sqrtBlockRange; blockColumn++) {
children.push(childBase | ((blockRow * sqrtBlockRange + blockColumn) << blockShift));
}
}
return children;
}
export function geometryToCells(geometry, resolution: bigint): Quadbin[] {

@@ -112,0 +138,0 @@ const zoom = Number(resolution);

import test from 'tape';
import {
cellToBoundary,
tileToCell,
cellToChildren,
cellToTile,

@@ -8,3 +10,3 @@ cellToParent,

getResolution,
cellToBoundary
hexToBigInt
} from 'quadbin';

@@ -35,3 +37,3 @@

test('Quadbin getParent', async t => {
test('Quadbin cellToParent', async t => {
let tile = {x: 134, y: 1238, z: 10};

@@ -54,9 +56,32 @@ const quadkey = tileToQuadkey(tile);

test('Quadbin cellToChildren', async t => {
const parentTile = { z: 8, x: 59, y: 97 };
const parent = tileToCell(parentTile);
t.deepEquals(cellToChildren(parent, 8n), [parent], 'children at resolution + 0');
// Order is row major, starting from NW and ending at SE.
t.deepEquals(
cellToChildren(parent, 9n).map(cellToTile),
[
{ z: 9, x: 118, y: 194 }, // nw
{ z: 9, x: 119, y: 194 }, // ne
{ z: 9, x: 118, y: 195 }, // sw
{ z: 9, x: 119, y: 195 } // se
],
'children at resolution + 1'
);
t.deepEquals(cellToChildren(parent, 10n).length, 16, 'children at resolution + 2');
t.end();
});
// Zoom:26 test not agreeing with Python
import PointGeometry from './data/PointGeometry.json' assert {type: 'json'};
import MultiPointGeometry from './data/MultiPointGeometry.json' assert {type: 'json'};
import LineStringGeometry from './data/LineStringGeometry.json' assert {type: 'json'};
import PolygonGeometry from './data/PolygonGeometry.json' assert {type: 'json'};
import PolygonAntimeridianGeometry from './data/PolygonAntimeridianGeometry.json' assert {type: 'json'};
import MultiPolygonGeometry from './data/MultiPolygonGeometry.json' assert {type: 'json'};
import PointGeometry from './data/PointGeometry.json' with {type: 'json'};
import MultiPointGeometry from './data/MultiPointGeometry.json' with {type: 'json'};
import LineStringGeometry from './data/LineStringGeometry.json' with {type: 'json'};
import PolygonGeometry from './data/PolygonGeometry.json' with {type: 'json'};
import PolygonAntimeridianGeometry from './data/PolygonAntimeridianGeometry.json' with {type: 'json'};
import MultiPolygonGeometry from './data/MultiPolygonGeometry.json' with {type: 'json'};
const testCases = [

@@ -63,0 +88,0 @@ PointGeometry,