Skip to content
/ usv-npm Public

Unicode Separated Values (USV) with Node Package Manager (NPM)

Notifications You must be signed in to change notification settings

SixArm/usv-npm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

USV-NPM: Unicode Separated Values (USV) ™ with Node Package Manager (NPM)

Start

Initialize:

mkdir usv-npm && cd $_

Add git

Run:

git init
git remote add origin [email protected]:SixArm/usv-npm.git
git branch -M main
touch .gitignore && git add -A && git commit -m "Init"
git push -u origin main

Verify:

git status

Result:

… Your branch is up to date with 'origin/main'.

Add NPM

Run:

npm init -y

Verify:

npm --version

Output:

10.5.2

Add TypeScript

Run:

npm install typescript --save-dev

Verify:

tsc -v

Output:

Version 5.4.5

Initialize:

tsc --init

Review:

cat tsconfig.json

Output:

Created a new tsconfig.json with:                                                                                       
  target: es2016
  module: commonjs
  strict: true
  esModuleInterop: true
  skipLibCheck: true
  forceConsistentCasingInFileNames: true

Create code

Create source code

Run:

mkdir src && cd $_
echo 'console.log("hello world")' > index.ts
tsc index.ts
node index.js

Output:

hello world

Commit:

git add index.{js,ts}
git commit -m "Add hello world"

Add Jest for testing

Run:

npm install jest ts-jest @types/jest --save-dev

Add a script to your file package.json:

"scripts": {
  "test": "jest"
}

Create file jest.config.js:

module.exports = {
  preset: "ts-jest",
  testEnvironment: "node",
};

Create source file src/sum.ts:

export function sum(a: number, b: number): number {
  return a + b;
}

Create corresponding test file tests/sum.test.ts:

import { sum } from "../src/sum";

describe("Math functions", () => {
  it("should sum two numbers correctly", () => {
    expect(sum(1, 2)).toEqual(3);
  });
});

Run:

npm test

Output:

 PASS  tests/sum.test.ts
  Math functions
    ✓ should sum two numbers correctly (1 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.653 s
Ran all test suites.

About

Unicode Separated Values (USV) with Node Package Manager (NPM)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published