npm package: @jnanda/a_library
Description: my sample library
Author: jnanda
Latest version: 1.1.0

# 🚀 Captain.js — Complete npm Publishing Guide

This document contains everything needed to build, structure, and publish `captain.js` to npm professionally.

---

# 1️⃣ Prerequisites

Make sure you have:

- Node.js installed
- npm installed
- Git installed
- GitHub account
- npm account

Check versions:

```bash
node -v
npm -v
git --version
```

---

# 2️⃣ Create Project Folder

```bash
mkdir captain-js
cd captain-js
```

---

# 3️⃣ Create Library File

Create:

```
captain.js
```

Add:

```javascript
(function (global) {

  const Captain = {

    sum: function(a, b) {
      return a + b;
    },

    multiply: function(a, b) {
      return a * b;
    },

    capitalize: function(str) {
      return str.charAt(0).toUpperCase() + str.slice(1);
    }

  };

  global.Captain = Captain;

})(typeof window !== "undefined" ? window : global);
```

---

# 4️⃣ Initialize npm

```bash
npm init -y
```

Edit `package.json`:

```json
{
  "name": "captain-js",
  "version": "1.0.0",
  "description": "A tiny OG JavaScript utility library",
  "main": "captain.js",
  "keywords": ["javascript", "utility", "library"],
  "author": "Your Name",
  "license": "MIT"
}
```

⚠️ Note: Package name must be unique on npm.

---

# 5️⃣ Create README.md

Create:

```
README.md
```

Example content:

```markdown
# Captain.js

A tiny OG JavaScript utility library.

## Installation

```bash
npm install captain-js
```

## CDN Usage

```html
<script src="https://cdn.jsdelivr.net/npm/captain-js@1.0.0/captain.js"></script>
```

## Example

```javascript
Captain.sum(2, 3); // 5
```
```

---

# 6️⃣ Create .gitignore

Create:

```
.gitignore
```

Add:

```
# Dependencies
node_modules/

# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Environment files
.env
.env.local

# OS files
.DS_Store
Thumbs.db

# Optional future build folders
dist/
build/
coverage/
```

### Why `.gitignore`?

It prevents unnecessary files (like `node_modules`) from being committed to GitHub.

---

# 7️⃣ Create LICENSE (MIT)

Create:

```
LICENSE
```

Add:

```
MIT License

Copyright (c) 2026 Your Name

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software...
```

(Use full MIT template from https://opensource.org/licenses/MIT)

### Why License?

Without a license, legally no one can use your code.

MIT allows:
- Commercial use
- Modification
- Distribution
- Private use

Requires:
- Keeping copyright notice

---

# 8️⃣ Initialize Git

```bash
git init
git add .
git commit -m "Initial commit"
```

---

# 9️⃣ Push to GitHub

Create a repository on GitHub named `captain-js`.

Then:

```bash
git remote add origin https://github.com/yourusername/captain-js.git
git branch -M main
git push -u origin main
```

---

# 🔟 Login to npm

```bash
npm login
```

Enter username, password, email, and OTP if required.

Check login:

```bash
npm whoami
```

---

# 1️⃣1️⃣ Publish to npm

```bash
npm publish
```

If successful:

```
+ captain-js@1.0.0
```

---

# 1️⃣2️⃣ CDN Usage (Automatic)

After publishing, your package is automatically available on CDN:

```
https://cdn.jsdelivr.net/npm/captain-js@1.0.0/captain.js
```

Use in HTML:

```html
<script src="https://cdn.jsdelivr.net/npm/captain-js@1.0.0/captain.js"></script>
```

---

# 1️⃣3️⃣ Updating Version

You cannot overwrite a published version.

Update version in `package.json`:

```json
"version": "1.0.1"
```

Then:

```bash
npm publish
```

---

# 1️⃣4️⃣ Semantic Versioning

Format:

```
MAJOR.MINOR.PATCH
```

Examples:

- 1.0.1 → Bug fix
- 1.1.0 → New feature
- 2.0.0 → Breaking change

---

# 📁 Final Folder Structure

```
captain-js/
│
├── captain.js
├── package.json
├── README.md
├── LICENSE
└── .gitignore
```

---

# 🏁 You Are Now

✔ A published npm package author  
✔ CDN-distributed globally  
✔ Properly licensed  
✔ Professionally structured  

---

# 🚀 Optional Next Steps

- Add minified build
- Add TypeScript definitions
- Add CI/CD auto publish
- Add automated version bumping
- Convert to ES Module + UMD

---

Captain.js is now officially live-ready.