From 71443e0695509a7fcf8a1b214e4ebf94ef2c3188 Mon Sep 17 00:00:00 2001 From: Paulius Varna Date: Thu, 15 Aug 2024 15:42:30 +0300 Subject: [PATCH] use native crypto.randomUUID() instead of hat module --- package-lock.json | 7 +------ package.json | 3 +-- src/api.js | 3 +-- src/feature_types/feature.js | 3 +-- src/feature_types/multi_feature.js | 3 +-- test/utils/create_feature.js | 5 +---- 6 files changed, 6 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 59c0f2d5b..1b0f88b33 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,8 +12,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" }, "devDependencies": { "@mapbox/cloudfriend": "^8.1.0", @@ -5019,10 +5018,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/hat": { - "version": "0.0.3", - "license": "MIT/X11" - }, "node_modules/hosted-git-info": { "version": "2.8.9", "dev": true, diff --git a/package.json b/package.json index d8ec3b287..b68c51954 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/api.js b/src/api.js index 0a99dc406..22c781597 100644 --- a/src/api.js +++ b/src/api.js @@ -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'; @@ -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'); diff --git a/src/feature_types/feature.js b/src/feature_types/feature.js index 0d5c6b21e..7c904e3a8 100644 --- a/src/feature_types/feature.js +++ b/src/feature_types/feature.js @@ -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; }; diff --git a/src/feature_types/multi_feature.js b/src/feature_types/multi_feature.js index 78f194075..a430af187 100644 --- a/src/feature_types/multi_feature.js +++ b/src/feature_types/multi_feature.js @@ -1,4 +1,3 @@ -import hat from 'hat'; import Feature from './feature.js'; import * as Constants from '../constants.js'; @@ -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: { diff --git a/test/utils/create_feature.js b/test/utils/create_feature.js index 317eabbc9..ce631d973 100644 --- a/test/utils/create_feature.js +++ b/test/utils/create_feature.js @@ -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;