UNPKG

1.15 kBJavaScriptView Raw
1"use strict";
2
3const pathUtil = require("path");
4const move = require("./move");
5const validate = require("./utils/validate");
6
7const validateInput = (methodName, path, newName) => {
8 const methodSignature = `${methodName}(path, newName)`;
9 validate.argument(methodSignature, "path", path, ["string"]);
10 validate.argument(methodSignature, "newName", newName, ["string"]);
11};
12
13// ---------------------------------------------------------
14// Sync
15// ---------------------------------------------------------
16
17const renameSync = (path, newName) => {
18 const newPath = pathUtil.join(pathUtil.dirname(path), newName);
19 move.sync(path, newPath);
20};
21
22// ---------------------------------------------------------
23// Async
24// ---------------------------------------------------------
25
26const renameAsync = (path, newName) => {
27 const newPath = pathUtil.join(pathUtil.dirname(path), newName);
28 return move.async(path, newPath);
29};
30
31// ---------------------------------------------------------
32// API
33// ---------------------------------------------------------
34
35exports.validateInput = validateInput;
36exports.sync = renameSync;
37exports.async = renameAsync;