SAP-BTP-Spielwiese/app1/node_modules/@sap/logging/lib/IdGenerator.js

24 lines
528 B
JavaScript
Raw Normal View History

'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;