Writing a JS Library
- https://en.wikipedia.org/wiki/%C2%A3sd
- P O U N D S,
S H I L L I N G S, A N D
P E N C E
💷💸💹
- Examples
- https://github.com/sindresorhus/year-days/blob/main/index.js
- ```
import leapYear from 'leap-year';
export default function yearDays(yearOrDate) {
return leapYear(yearOrDate) ? 366 : 365;
}
```
- https://github.com/date-fns/date-fns/blob/master/src/index.js
- ```
// This file is generated automatically by `scripts/build/indices.js`.
export { default as add } from './add/index'
...
export { default as toDate } from './toDate/index'
export * from './constants/index'
```
- My first time writing an npm package/JS library
- What tech shall we use?
- Methods
- looked at uvu ... too weird
- Properties
- L E A R N I N G S
- esbuild
- If you `export` one thing as default, then when you import it you need to give it a name; you can't use `*`!
- Writing typescript classes
https://www.typescriptlang.org/docs/handbook/2/classes.html#readonly
- publish
- USING IT
- In the browser
- ```
<script type="module">
import {lsd} from 'https://unpkg.com/old-money@1.0.1/dist/index.js';
var money = new lsd(1000);
console.log(money.toString());
</script>
```
Writing a JS Library
- https://en.wikipedia.org/wiki/%C2%A3sd
- P O U N D S,
S H I L L I N G S, A N D
P E N C E
💷💸💹
- Examples
- https://github.com/sindresorhus/year-days/blob/main/index.js
- ```
import leapYear from 'leap-year';
export default function yearDays(yearOrDate) {
return leapYear(yearOrDate) ? 366 : 365;
}
```
- https://github.com/date-fns/date-fns/blob/master/src/index.js
- ```
// This file is generated automatically by `scripts/build/indices.js`.
export { default as add } from './add/index'
...
export { default as toDate } from './toDate/index'
export * from './constants/index'
```
- My first time writing an npm package/JS library
- What tech shall we use?
- Methods
- looked at uvu ... too weird
- Properties
- L E A R N I N G S
- esbuild
- If you `export` one thing as default, then when you import it you need to give it a name; you can't use `*`!
- Writing typescript classes
https://www.typescriptlang.org/docs/handbook/2/classes.html#readonly
- publish
- USING IT
- In the browser
- ```
<script type="module">
import {lsd} from 'https://unpkg.com/old-money@1.0.1/dist/index.js';
var money = new lsd(1000);
console.log(money.toString());
</script>
```