-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from nrabinowitz/legacy-api
This adds a legacy API wrapper, available from h3-js/legacy, which exports the v4 functions using the v3 names. The intent is to help ease migration to the v4 library. In addition to allowing users to put off migrating their code, this provides a path, albeit awkward, to avoid bundling two versions of the library when dependencies have not upgraded to v4, by rewriting dependency import paths at build time to point to the legacy API.
- Loading branch information
Showing
11 changed files
with
1,977 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright 2022 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"), | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
module.exports = require('./dist/legacy'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2022 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"), | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
module.exports = { | ||
UNITS: 'UNITS', | ||
h3IndexToSplitLong: 'h3IndexToSplitLong', | ||
splitLongToH3Index: 'splitLongToH3Index', | ||
h3IsValid: 'isValidCell', | ||
h3IsPentagon: 'isPentagon', | ||
h3IsResClassIII: 'isResClassIII', | ||
h3GetBaseCell: 'getBaseCellNumber', | ||
h3GetFaces: 'getIcosahedronFaces', | ||
h3GetResolution: 'getResolution', | ||
geoToH3: 'latLngToCell', | ||
h3ToGeo: 'cellToLatLng', | ||
h3ToGeoBoundary: 'cellToBoundary', | ||
h3ToParent: 'cellToParent', | ||
h3ToChildren: 'cellToChildren', | ||
h3ToCenterChild: 'cellToCenterChild', | ||
kRing: 'gridDisk', | ||
kRingDistances: 'gridDiskDistances', | ||
hexRing: 'gridRingUnsafe', | ||
polyfill: 'polygonToCells', | ||
h3SetToMultiPolygon: 'cellsToMultiPolygon', | ||
compact: 'compactCells', | ||
uncompact: 'uncompactCells', | ||
h3IndexesAreNeighbors: 'areNeighborCells', | ||
getH3UnidirectionalEdge: 'cellsToDirectedEdge', | ||
getOriginH3IndexFromUnidirectionalEdge: 'getDirectedEdgeOrigin', | ||
getDestinationH3IndexFromUnidirectionalEdge: 'getDirectedEdgeDestination', | ||
h3UnidirectionalEdgeIsValid: 'isValidDirectedEdge', | ||
getH3IndexesFromUnidirectionalEdge: 'directedEdgeToCells', | ||
getH3UnidirectionalEdgesFromHexagon: 'originToDirectedEdges', | ||
getH3UnidirectionalEdgeBoundary: 'directedEdgeToBoundary', | ||
h3Distance: 'gridDistance', | ||
h3Line: 'gridPathCells', | ||
experimentalH3ToLocalIj: 'cellToLocalIj', | ||
experimentalLocalIjToH3: 'localIjToCell', | ||
pointDist: 'greatCircleDistance', | ||
cellArea: 'cellArea', | ||
exactEdgeLength: 'exactEdgeLength', | ||
hexArea: 'getHexagonAreaAvg', | ||
edgeLength: 'getHexagonEdgeLengthAvg', | ||
numHexagons: 'getNumCells', | ||
getRes0Indexes: 'getRes0Cells', | ||
getPentagonIndexes: 'getPentagons', | ||
degsToRads: 'degsToRads', | ||
radsToDegs: 'radsToDegs' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2022 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"), | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @fileoverview | ||
* Create the module for the legacy v3 API and write to dist. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const mapping = require('../lib/legacy-mapping'); | ||
|
||
const content = ` | ||
const h3v4 = require('./h3-js'); | ||
module.exports = { | ||
${Object.entries(mapping) | ||
.map(([oldName, newName]) => `${oldName}: h3v4.${newName}`) | ||
.join(',\n')} | ||
}; | ||
`; | ||
|
||
fs.writeFileSync(path.join(__dirname, '../dist/legacy.js'), content, 'utf-8'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2022 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"), | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @fileoverview | ||
* Create Typescript types for the legacy v3 API and write to dist. Depends | ||
* on the current v4 types already being generated in dist. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const mapping = require('../lib/legacy-mapping'); | ||
|
||
let content = fs.readFileSync(path.join(__dirname, '../dist/types.d.ts'), 'utf-8'); | ||
|
||
for (const [oldName, newName] of Object.entries(mapping)) { | ||
const regex = new RegExp(`\\b${newName}\\b`, 'g'); | ||
content = content.replace(regex, oldName); | ||
} | ||
|
||
fs.writeFileSync(path.join(__dirname, '../dist/legacy-types.d.ts'), content, 'utf-8'); |
Oops, something went wrong.