Topics
- Functional Programming in JavaScript
- Building a Modern JavaScript Library with Vite
- Unit Testing with Jest and Vitest
Resources
- 📖 Check out the handbook
- 📜 Check out the slide
- 💪 Work in groups
- 🔨 Collaborate with Live Share
Workshop
Example of method chaining
Implementations in defferent languages:
| 1 | collect([1, 2, 3]) | 
Create test case for “map” function
Create an index.test.ts file in src folder.
| 1 | import { test, expect } from 'vitest'; | 
Run test command.
| 1 | npm run test | 
Implement “map” function
Update index.ts file in src folder, and create a Collection class.
| 1 | class Collection { | 
Implement a map function for the class, and return the class itself.
| 1 | import { | 
Implement a toArray function for the class, and return the array data.
| 1 | class Collection { | 
Create a collect helper function, and return a Collection instance.
| 1 | // ... | 
Run test command.
| 1 | npm run test | 
Implement more functions
Implement more functions for the class with TDD:
- map ✅
- every
- filter
- find
- forEach
- includes
- reduce
- reject
- size
- some
Finally, run coverage command.
| 1 | npm run coverage | 
Publish to NPM
Build the package before publishing.
| 1 | npm run build | 
Login to NPM.
| 1 | npm login | 
Update package.json file.
| 1 | { | 
Publish to NPM with dry run.
| 1 | npm publish --dry-run | 
Publish to NPM.
| 1 | npm publish --access=public | 
Use package
Try with UMD module
Update index.html file.
| 1 | 
 | 
Try with ES module
Install dependencies.
| 1 | npm install @memochou1993/collection-js@latest | 
Update index.html file.
| 1 | 
 | 
Start a server.
| 1 | npm run dev |