Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native crypto.randomUUID() instead of hat module #1274

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
"@mapbox/geojson-area": "^0.2.2",
"@mapbox/geojson-normalize": "^0.0.1",
"@mapbox/point-geometry": "^0.1.0",
"fast-deep-equal": "^3.1.3",
"hat": "0.0.3"
"fast-deep-equal": "^3.1.3"
},
"files": [
"src",
Expand Down
3 changes: 1 addition & 2 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import isEqual from 'fast-deep-equal';
import normalize from '@mapbox/geojson-normalize';
import hat from 'hat';
import featuresAt from './lib/features_at.js';
import stringSetsAreEqual from './lib/string_sets_are_equal.js';
import * as Constants from './constants.js';
Expand Down Expand Up @@ -76,7 +75,7 @@ export default function(ctx, api) {
const featureCollection = JSON.parse(JSON.stringify(normalize(geojson)));

const ids = featureCollection.features.map((feature) => {
feature.id = feature.id || hat();
feature.id = feature.id || crypto.randomUUID();

if (feature.geometry === null) {
throw new Error('Invalid geometry: null');
Expand Down
3 changes: 1 addition & 2 deletions src/feature_types/feature.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import hat from 'hat';
import * as Constants from '../constants.js';

const Feature = function(ctx, geojson) {
this.ctx = ctx;
this.properties = geojson.properties || {};
this.coordinates = geojson.geometry.coordinates;
this.id = geojson.id || hat();
this.id = geojson.id || crypto.randomUUID();
this.type = geojson.geometry.type;
};

Expand Down
3 changes: 1 addition & 2 deletions src/feature_types/multi_feature.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import hat from 'hat';
import Feature from './feature.js';
import * as Constants from '../constants.js';

Expand Down Expand Up @@ -33,7 +32,7 @@ MultiFeature.prototype = Object.create(Feature.prototype);
MultiFeature.prototype._coordinatesToFeatures = function(coordinates) {
const Model = this.model.bind(this);
return coordinates.map(coords => new Model(this.ctx, {
id: hat(),
id: crypto.randomUUID(),
type: Constants.geojsonTypes.FEATURE,
properties: {},
geometry: {
Expand Down
5 changes: 1 addition & 4 deletions test/utils/create_feature.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import hat from 'hat';
import getGeoJSON from './get_geojson.js';

const hatRack = hat.rack();

export default function createFeature(featureType) {
const feature = Object.assign({
id: hatRack(),
id: crypto.randomUUID(),
properties: {}
}, getGeoJSON(featureType));
feature.toGeoJSON = () => feature;
Expand Down