1 | "use strict";
|
2 |
|
3 | const pathUtil = require("path");
|
4 | const move = require("./move");
|
5 | const validate = require("./utils/validate");
|
6 |
|
7 | const validateInput = (methodName, path, newName, options) => {
|
8 | const methodSignature = `${methodName}(path, newName, [options])`;
|
9 | validate.argument(methodSignature, "path", path, ["string"]);
|
10 | validate.argument(methodSignature, "newName", newName, ["string"]);
|
11 | validate.options(methodSignature, "options", options, {
|
12 | overwrite: ["boolean"]
|
13 | });
|
14 |
|
15 | if (pathUtil.basename(newName) !== newName) {
|
16 | throw new Error(
|
17 | `Argument "newName" passed to ${methodSignature} should be a filename, not a path. Received "${newName}"`
|
18 | );
|
19 | }
|
20 | };
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | const renameSync = (path, newName, options) => {
|
27 | const newPath = pathUtil.join(pathUtil.dirname(path), newName);
|
28 | move.sync(path, newPath, options);
|
29 | };
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | const renameAsync = (path, newName, options) => {
|
36 | const newPath = pathUtil.join(pathUtil.dirname(path), newName);
|
37 | return move.async(path, newPath, options);
|
38 | };
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | exports.validateInput = validateInput;
|
45 | exports.sync = renameSync;
|
46 | exports.async = renameAsync;
|