29
loading...
This website collects cookies to deliver better user experience
cross-path
.cross-path
is going to be an npm package that will convert darwin paths to win32 and win32 paths to darwin.npx create-foss-files --javascript
contributing.md
file. package.json
file. Safe to say that this file contains all the metadata of your project. Open it.cross-path
, some description to explain the functionality of the package, and fill out other stuff as well.{
"name": "cross-paths",
"version": "1.0.0",
"description": "Converts paths from darwin to win32 platform and vice versa",
"repository": "https://github.com/msaaddev/cross-paths",
"author": {
"name": "Saad Irfan",
"email": "[email protected]",
"url": "https://twitter.com/msaaddev"
},
"main": "index.js",
"license": "MIT",
"scripts": {
"format": "prettier --write \"./**/*.{js,json}\"",
},
"keywords": [
"cross paths",
"windows to unix paths",
"unix to windows path",
"darwin to windows path",
"windows to darwin path",
"path converter",
"convert paths",
"Saad Irfan",
"msaaddev"
],
"devDependencies": {
"prettier": "^2.3.2"
},
}
index.js
file for this. I am not going to waste your time with this part of the process since it varies from package to package.cross-path
package./**
*
* Author: Saad Irfan
* GitHub: msaaddev
* Twitter: https://twitter.com/msaaddev
*/
const logSymbols = require('log-symbols');
const nodePath = require('path');
const { toUnix } = require('upath');
/**
*
*
* @param {path} - darwin path
* @returns {path} - win32 path
*/
const darwinToWin32 = path => {
if (!path) {
console.log(`${logSymbols.error} Please provide a valid path`);
return null;
}
return nodePath.win32.normalize(path);
};
/**
*
*
* @param {path} - win32 path
* @returns {path} - darwin path
*/
const win32ToDarwin = path => {
if (!path) {
console.log(`${logSymbols.error} Please provide a valid path`);
return null;
}
return toUnix(path);
};
module.exports = {
darwinToWin32,
win32ToDarwin
};
module.exports
does. module.exports
exports anything you set equal to it. You can export anything (variable, object, arrays, functions, classes) from a file through this and it will export it as a module. If you look at the code above, you will notice that I am exporting an object through module.exports
. The object contains two functions. So in turn, I am exporting two functions from this file via an object.module.exports
.module.exports
to modularize your code across multiple files. This will help the readability of your codebase. require
keyword. ⚡️index.js
file using the require
keyword. Just so you know, this is how someone is going to use your code in their project.readme.md
file and write things like features, installation guide, usage, any other information that you think is important, etc.npm login
npm publish
A package with the same name already exists. In this case, either you need to change the name of your package or make a scoped package. Read more about scoped package here.
You have not updated the version number of your package before publishing it again. Everytime you have made a change and now you are publishing your package again, you would need to change its version. It is because you can not publish again on an existing version. I would suggest following semantic versioning.