SAP-BTP-Spielwiese/app1/node_modules/@sap/logging/lib/IdGenerator.js
Markus Rettig 775ac7b58c completed step 3 from the tutorial
you must login with an BTP account in order to see the app
2024-02-08 16:13:36 +01:00

23 lines
528 B
JavaScript

'use strict';
const moment = require('moment');
class IdGenerator {
constructor() {
this._lastUsedTimestamp = null;
this._counter = 0;
}
nextId() {
const currentTimestamp = moment().valueOf();
if (currentTimestamp === this._lastUsedTimestamp) {
return currentTimestamp.toString(36) + '.' + (++this._counter).toString(36);
} else {
this._counter = 0;
this._lastUsedTimestamp = currentTimestamp;
return currentTimestamp.toString(36);
}
}
}
module.exports = IdGenerator;