Skip to content

Commit ae82659

Browse files
committed
Initial commit
1 parent db974d1 commit ae82659

File tree

14 files changed

+152
-66
lines changed

14 files changed

+152
-66
lines changed

.github/workflows/npm-publish.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Node.js build and publish package
1+
name: Node.js build and publish package on GitHub Registry
22

33
on:
44
release:
@@ -12,20 +12,22 @@ jobs:
1212
- uses: actions/setup-node@v3
1313
with:
1414
node-version: 16
15-
- run: npm i
15+
- run: npm ci
1616
- run: npm test
1717

18-
publish-npm:
18+
publish-gpr:
1919
needs: build
2020
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
2124
steps:
2225
- uses: actions/checkout@v3
2326
- uses: actions/setup-node@v3
2427
with:
2528
node-version: 16
26-
registry-url: https://registry.npmjs.org/
27-
- run: npm i
28-
- run: npm run build
29+
registry-url: https://npm.pkg.github.com/
30+
- run: npm ci
2931
- run: npm publish
3032
env:
31-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
33+
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/gallium

README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
<p align="center">
2-
<img width="100px" src="https://raw.githubusercontent.com/hebertcisco/ts-npm-package-boilerplate/main/.github/images/favicon512x512-npm.png" align="center" alt=":package: ts-npm-package-boilerplate" />
3-
<h2 align="center">:package: ts-npm-package-boilerplate</h2>
4-
<p align="center">TypeScript NPM Module Boilerplate</p>
2+
<img width="100px" src="https://raw.githubusercontent.com/localtools/nodejs-base64/main/.github/images/favicon512x512-npm.png" align="center" alt=":package: nodejs-base64" />
3+
<h2 align="center">:package: nodejs-base64</h2>
4+
<p align="center">Node.js Base64 Text Encoder/Decoder</p>
55
<p align="center">
6-
<a href="https://github.com/hebertcisco/ts-npm-package-boilerplate/issues">
7-
<img alt="Issues" src="https://img.shields.io/github/issues/hebertcisco/ts-npm-package-boilerplate?style=flat&color=336791" />
6+
<a href="https://github.com/localtools/nodejs-base64/issues">
7+
<img alt="Issues" src="https://img.shields.io/github/issues/localtools/nodejs-base64?style=flat&color=336791" />
88
</a>
9-
<a href="https://github.com/hebertcisco/ts-npm-package-boilerplate/pulls">
10-
<img alt="GitHub pull requests" src="https://img.shields.io/github/issues-pr/hebertcisco/ts-npm-package-boilerplate?style=flat&color=336791" />
9+
<a href="https://github.com/localtools/nodejs-base64/pulls">
10+
<img alt="GitHub pull requests" src="https://img.shields.io/github/issues-pr/localtools/nodejs-base64?style=flat&color=336791" />
1111
</a>
12-
<a href="https://github.com/hebertcisco/ts-npm-package-boilerplate">
13-
<img alt="GitHub Downloads" src="https://img.shields.io/npm/dw/ts-npm-package-boilerplate?style=flat&color=336791" />
12+
<a href="https://github.com/localtools/nodejs-base64">
13+
<img alt="GitHub Downloads" src="https://img.shields.io/npm/dw/nodejs-base64?style=flat&color=336791" />
1414
</a>
15-
<a href="https://github.com/hebertcisco/ts-npm-package-boilerplate">
16-
<img alt="GitHub Total Downloads" src="https://img.shields.io/npm/dt/ts-npm-package-boilerplate?color=336791&label=Total%20downloads" />
15+
<a href="https://github.com/localtools/nodejs-base64">
16+
<img alt="GitHub Total Downloads" src="https://img.shields.io/npm/dt/nodejs-base64?color=336791&label=Total%20downloads" />
1717
</a>
18-
<a href="https://github.com/hebertcisco/ts-npm-package-boilerplate">
19-
<img alt="GitHub release" src="https://img.shields.io/github/release/hebertcisco/ts-npm-package-boilerplate.svg?style=flat&color=336791" />
18+
<a href="https://github.com/localtools/nodejs-base64">
19+
<img alt="GitHub release" src="https://img.shields.io/github/release/localtools/nodejs-base64.svg?style=flat&color=336791" />
2020
</a>
2121
<br />
2222
<br />
23-
<a href="https://github.com/hebertcisco/ts-npm-package-boilerplate/issues/new/choose">Report Bug</a>
24-
<a href="https://github.com/hebertcisco/ts-npm-package-boilerplate/issues/new/choose">Request Feature</a>
23+
<a href="https://github.com/localtools/nodejs-base64/issues/new/choose">Report Bug</a>
24+
<a href="https://github.com/localtools/nodejs-base64/issues/new/choose">Request Feature</a>
2525
</p>
2626
<h3 align="center">Systems on which it has been tested:</h3>
2727
<p align="center">
@@ -37,33 +37,36 @@
3737
</p>
3838
<p align="center">Did you like the project? Please, considerate <a href="https://www.buymeacoffee.com/hebertcisco">a donation</a> to help improve!</p>
3939

40-
<p align="center"><strong>TypeScript NPM Module Boilerplate</strong>✨</p>
40+
<p align="center"><strong>Node.js Base64 Text Encoder/Decoder</strong>✨</p>
4141

42-
[![codecov](https://codecov.io/gh/hebertcisco/ts-npm-package-boilerplate/branch/main/graph/badge.svg?token=Q9fr548J0D)](https://codecov.io/gh/hebertcisco/ts-npm-package-boilerplate)
42+
[![codecov](https://codecov.io/gh/localtools/nodejs-base64/branch/main/graph/badge.svg?token=Q9fr548J0D)](https://codecov.io/gh/localtools/nodejs-base64)
4343

4444
# Getting started
4545

4646
## Installation
4747

48-
> Clone this repository: `git clone https://github.com/hebertcisco/ts-npm-package-boilerplate`
48+
> Clone this repository: `git clone https://github.com/localtools/nodejs-base64`
4949
50-
### Open the directory and run the script line:
50+
### Open the directory and run the script line
5151

5252
```bash
53-
cd ts-npm-package-boilerplate
53+
cd nodejs-base64
5454
```
55+
5556
```bash
5657
npm i # or yarn
5758
```
59+
5860
```bash
5961
rm -rf .git && git init && git add . && git commit -m "Initial commit" #Optional
6062
```
63+
6164
Or create use the button "Use this template"
6265

6366
Edit the Icon on Figma:
6467

65-
<a href="https://www.figma.com/file/vpevGX3j9tmtW8OyLQ9eUm/ts-npm-package-boilerplate-icon?node-id=0%3A1">
66-
<img alt="Figma Icon" src="https://raw.githubusercontent.com/hebertcisco/ts-npm-package-boilerplate/main/.github/images/figma-badge.png"/>
68+
<a href="https://www.figma.com/file/vpevGX3j9tmtW8OyLQ9eUm/nodejs-base64-icon?node-id=0%3A1">
69+
<img alt="Figma Icon" src="https://raw.githubusercontent.com/localtools/nodejs-base64/main/.github/images/figma-badge.png"/>
6770
</a>
6871

6972
## 🤝 Contributing

jest-e2e.cjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
moduleFileExtensions: ['js', 'json', 'ts'],
3+
rootDir: '.',
4+
testEnvironment: 'node',
5+
testRegex: '.e2e-spec.ts$',
6+
transform: {
7+
'^.+\\.(t|j)s$': 'ts-jest',
8+
},
9+
};
File renamed without changes.

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,50 @@
11
{
2-
"name": "ts-npm-package-boilerplate",
3-
"version": "0.2.1",
4-
"description": "TypeScript NPM Module Boilerplate",
2+
"name": "@localtools/base64",
3+
"version": "0.0.1",
4+
"description": "Node.js Base64 Text Encoder/Decoder",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
77
"scripts": {
88
"build": "tsc",
99
"format": "prettier --write \"src/**/*.(js|ts)\"",
1010
"lint": "eslint src --ext .js,.ts",
1111
"lint:fix": "eslint src --fix --ext .js,.ts",
12-
"test": "jest --config jest.config.js",
12+
"test": "jest --config jest.config.cjs",
13+
"test:cov": "npm test -- --coverage",
14+
"test:watch": "npm test -- --watch",
15+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
16+
"test:e2e": "npm test -- --config jest-e2e.cjs",
1317
"prepare": "npm run build",
1418
"prepublishOnly": "npm test && npm run lint",
1519
"preversion": "npm run lint",
1620
"version": "npm run format && git add -A src",
1721
"postversion": "git push && git push --tags"
1822
},
23+
"publishConfig": {
24+
"registry": "https://npm.pkg.github.com"
25+
},
1926
"repository": {
2027
"type": "git",
21-
"url": "git+https://github.com/hebertcisco/ts-npm-package-boilerplate.git"
28+
"url": "git+https://github.com/localtools/nodejs-base64.git"
2229
},
2330
"keywords": [
24-
"boilerplate",
25-
"typescript"
31+
"base64",
32+
"encoding",
33+
"decoding",
34+
"text",
35+
"string",
36+
"binary",
37+
"data",
38+
"convert",
39+
"transformation",
40+
"utility"
2641
],
2742
"author": "Hebert Cisco",
2843
"license": "MIT",
2944
"bugs": {
30-
"url": "https://github.com/hebertcisco/ts-npm-package-boilerplate/issues"
45+
"url": "https://github.com/localtools/nodejs-base64/issues"
3146
},
32-
"homepage": "https://github.com/hebertcisco/ts-npm-package-boilerplate#readme",
47+
"homepage": "https://github.com/localtools/nodejs-base64#readme",
3348
"devDependencies": {
3449
"@types/jest": "29.2.4",
3550
"@typescript-eslint/eslint-plugin": "5.46.0",

src/__tests__/index.test.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/core/Base64.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import NodeBuffer from 'buffer';
2+
3+
import type { EncodeArgs } from '../shared/types/Base64.type';
4+
import type { DecodeArgs } from '../shared/types/Base64.type';
5+
6+
export class Base64 {
7+
public static encode(args: EncodeArgs): string {
8+
const { text } = args;
9+
if (!text) {
10+
throw new Error('Invalid text');
11+
}
12+
return NodeBuffer.Buffer.from(text).toString(args.encoding || 'base64', args.start, args.end);
13+
}
14+
15+
public static decode(args: DecodeArgs): string {
16+
const { base64Text } = args;
17+
if (!base64Text) {
18+
throw new Error('Invalid text');
19+
}
20+
return NodeBuffer.Buffer.from(base64Text, args.fromEncoding || 'base64').toString(args.outputEncoding || 'utf8');
21+
}
22+
}
23+
export default Base64;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Base64 } from '../Base64';
2+
3+
describe('Base64', () => {
4+
it('should encode and decode text correctly', () => {
5+
const text = 'hello world';
6+
const encodedText = Base64.encode({ text });
7+
const decodedText = Base64.decode({ base64Text: encodedText });
8+
expect(decodedText).toEqual(text);
9+
});
10+
});

0 commit comments

Comments
 (0)