Skip to content

Commit

Permalink
use native crypto.randomUUID() instead of hat module
Browse files Browse the repository at this point in the history
  • Loading branch information
varna committed Aug 15, 2024
1 parent 358fa9e commit 71443e0
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 18 deletions.
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

0 comments on commit 71443e0

Please sign in to comment.