Skip to content

Commit 2c888e7

Browse files
ian-wdiBotPeaches
authored andcommitted
refactor: uuid filename
1 parent 1229a9a commit 2c888e7

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/index.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ type CanvasState = {
99
alpha: string;
1010
};
1111

12+
function generateUniqueFilename() {
13+
var dt = new Date().getTime();
14+
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
15+
/[xy]/g,
16+
function (c) {
17+
var r = (dt + Math.random() * 16) % 16 | 0;
18+
dt = Math.floor(dt / 16);
19+
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
20+
},
21+
);
22+
return uuid;
23+
}
24+
1225
export default class RNSketchCanvas extends React.Component<
1326
RNSketchCanvasProps,
1427
CanvasState
@@ -124,22 +137,11 @@ export default class RNSketchCanvas extends React.Component<
124137
p.cropToImageSize || false,
125138
);
126139
} else {
127-
const date = new Date();
128140
this._sketchCanvas.save(
129141
'png',
130142
false,
131143
'',
132-
date.getFullYear() +
133-
'-' +
134-
(date.getMonth() + 1) +
135-
'-' +
136-
('0' + date.getDate()).slice(-2) +
137-
' ' +
138-
('0' + date.getHours()).slice(-2) +
139-
'-' +
140-
('0' + date.getMinutes()).slice(-2) +
141-
'-' +
142-
('0' + date.getSeconds()).slice(-2),
144+
generateUniqueFilename(),
143145
true,
144146
true,
145147
false,

0 commit comments

Comments
 (0)