From b29c88af3ae9eda804317905645bfe232486e0e6 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 19 Mar 2024 17:01:33 -0400 Subject: [PATCH] chore(docs): add advanced usage section --- readme.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/readme.md b/readme.md index 3b765be..024271d 100644 --- a/readme.md +++ b/readme.md @@ -111,6 +111,30 @@ function example(value: OnlyDaysAndWeeks) { example('5.2 days'); ``` +## Advanced Usage + +As of `v3.0`, you can import `parse` and `format` separately. + +```ts +import { parse, format } from 'ms'; + +parse('1h'); // 3600000 + +format(2000); // "2s" +``` + +If you want strict type checking for the input value, you can use `parseStrict`. + +```ts +import { parseStrict } from 'ms'; + +parseStrict('1h'); // 3600000 + +function example(s: string) { + return parseStrict(str); // tsc error +} +``` + ## Edge Runtime Support `ms` is compatible with the [Edge Runtime](https://edge-runtime.vercel.app/). It can be used inside environments like [Vercel Edge Functions](https://vercel.com/edge) as follows: