本文整理匯總了TypeScript中UUID.v4函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript v4函數的具體用法?TypeScript v4怎麽用?TypeScript v4使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了v4函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: before
before(async () => {
await esArchiver.load('empty_kibana');
await sourceConfigurationService.createConfiguration('default', {
name: 'Test Source',
logColumns: [
{
timestampColumn: {
id: uuidv4(),
},
},
{
fieldColumn: {
id: uuidv4(),
field: 'host.name',
},
},
{
fieldColumn: {
id: uuidv4(),
field: 'event.dataset',
},
},
{
messageColumn: {
id: uuidv4(),
},
},
],
});
});
示例2: v4
export const addTodo = (text: string) => ({
type: 'ADD_TODO',
payload: {
id: v4(),
text
}
});
示例3: produce
produce(state, draftState => {
switch (action.type) {
case 'PUBLISH_NOTIFICATION': {
const {notification} = action.payload
const publishedNotification = {
...notification,
id: uuid.v4(),
}
const matchIndex = state.findIndex(
n => n.type && notification.type && n.type === notification.type
)
const isUnique = matchIndex === -1
if (isUnique) {
draftState.unshift(publishedNotification)
}
return
}
case 'DISMISS_NOTIFICATION': {
const {id} = action.payload
return draftState.filter(n => n.id !== id)
}
case 'DISMISS_ALL_NOTIFICATIONS': {
return []
}
}
})
示例4: async
router.get('/', async (req: express.Request, res: express.Response) => {
const id = uuid.v4();
const timer = setInterval(() => {
res.write('event:keepalive\ndata:\n\n');
}, 30000);
req.socket.setKeepAlive(true);
req.socket.setTimeout(0);
req.connection.on('close', () => {
clearInterval(timer);
delete req.app.locals.pushClients[id];
res.end();
});
req.app.locals.pushClients[id] = res;
// The no-transform value of the Cache-Control header tells the
// compresssion middleware not to compress this
// response. Otherwise, the client never sees any of the writes.
res.writeHead(200, {
'Cache-Control': 'no-cache, no-transform',
'Connection': 'keep-alive',
'Content-Type': 'text/event-stream',
'X-Accel-Buffering': 'no',
});
res.write('event:connection\ndata:\n\n');
});
示例5: function
$request(reqOut, function (err: Error, message: any, body: any): void {
console.log('*************************');
console.log('' + vertex + ' ' + targetUrl);
console.log('-------------------------');
console.dir(headers);
console.log('=========================');
console.dir(body);
if (params && body && !params.id && !_.isArray(body)) {
body.id = body.id || uuid.v4();
body = [body];
}
else if (_.isArray(body)) {
_.each(body, function (item: any) {
item.id = item.id || uuid.v4();
});
}
if (!err) {
res
.status(message.statusCode)
.send(body);
}
else {
res.serverError(err);
}
})
示例6: it
it('should pass list authorization', async () => {
const route = buildRoute({type: 'destroy', byId: false, byList: true, authorization})
const body = [uuid(), uuid()]
const req = {grants, body}
await utils.runMiddleware(route.middleware, req)
expect(destroyStub).toHaveBeenCalledTimes(2)
})
示例7: it
it('should pass list authorization', async () => {
const route = buildRoute({type: 'update', byId: false, byList: true, authorization})
const body = [{id: uuid(), ...utils.defaultUser}, {id: uuid(), ...utils.defaultUser}]
const req = {grants, body}
const {res} = await utils.runMiddleware(route.middleware, req)
expect(await res.promise).toEqual(req.validated.body)
expect(updateAllStub).toHaveBeenCalledTimes(1)
})
示例8: _validateAnalyticsSharingUuid
function _validateAnalyticsSharingUuid(value: string) {
if (value == '') {
return uuidV4();
} else {
return value;
}
}