Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanga-Ganapathy committed Apr 6, 2024
1 parent f3e6944 commit 93dd23b
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 63 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-humans-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opentf/std": patch
---

Updated readme.
72 changes: 50 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

## Installation

Install it using your favourite package manager.

```sh
npm install @opentf/std
```
Expand All @@ -44,31 +46,51 @@ pnpm add @opentf/std
bun add @opentf/std
```

```sh
deno add @opentf/std
```

## Usage

```ts
import {
isNum,
pascalCase,
sort,
clone,
isEql,
isEqlArr,
sleep,
} from "@opentf/std";
Let’s explore some of the library’s capabilities:

1. Checking if a Value is Numeric:

isNum(NaN); //=> false
```js
import { isNum } from "@opentf/std";

pascalCase("pascal case"); //=> PascalCase
console.log(isNum(NaN)); //=> false
```

sort([1, 10, 21, 2], "desc"); //=> [ 21, 10, 2, 1 ]
2. Converting Strings to PascalCase:

const obj = {
a: 1,
b: "abc",
c: new Map([["key", "val"]]),
};
clone(obj); // It returns deeply cloned value.
```js
import { pascalCase } from "@opentf/std";

console.log(pascalCase("pascal case")); //=> PascalCase
```

3. Sorting an Array in Descending Order:

```js
import { sort } from "@opentf/std";

console.log(sort([1, 10, 21, 2], "desc")); //=> [21, 10, 2, 1]
```

4. Deep Cloning an Object:

```js
import { clone } from "@opentf/std";

const obj = { a: 1, b: "abc", c: new Map([["key", "val"]]) };
console.log(clone(obj)); // Deeply cloned value
```

5. Checking Equality of Objects & Arrays:

```js
import { isEql, isEqlArr } from "@opentf/std";

const mapA = new Map([
["a", 1],
Expand All @@ -78,11 +100,17 @@ const mapB = new Map([
["b", 2],
["a", 1],
]);
isEql(mapA, mapB); //=> false
console.log(isEql(mapA, mapB)); //=> false

console.log(isEqlArr([1, 2, 3], [2, 3, 1])); //=> true
```

6. Adding a Delay (1 second) with sleep:

isEqlArr([1, 2, 3], [2, 3, 1]); //=> true
```js
import { sleep } from "@opentf/std";

await sleep(1000); // It suspends the exection for 1 second.
await sleep(1000); // Suspends execution for 1 second
```

## API
Expand Down
60 changes: 44 additions & 16 deletions apps/docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,60 @@ import { Tabs, Callout } from "nextra/components";
</Tabs>

## Usage
Let’s explore some of the library’s capabilities:

```ts
import { isNum, pascalCase, sort, clone, isEql, isEqlArr, sleep } from "@opentf/std";
1. Checking if a Value is Numeric:
```js
import { isNum } from "@opentf/std";

isNum(NaN); //=> false
console.log(isNum(NaN)); //=> false
```

2. Converting Strings to PascalCase:
```js
import { pascalCase } from "@opentf/std";

console.log(pascalCase("pascal case")); //=> PascalCase
```

pascalCase('pascal case'); //=> PascalCase
3. Sorting an Array in Descending Order:

sort([1, 10, 21, 2], 'desc'); //=> [ 21, 10, 2, 1 ]
```js
import { sort } from "@opentf/std";

const obj = {
a: 1,
b: 'abc',
c: new Map([['key', 'val']])
};
clone(obj); // It returns deeply cloned value.
console.log(sort([1, 10, 21, 2], "desc")); //=> [21, 10, 2, 1]
```

const mapA = new Map([ ['a', 1], ['b', 2] ])
const mapB = new Map([ ['b', 2], ['a', 1] ])
isEql(mapA, mapB); //=> false
4. Deep Cloning an Object:

isEqlArr([1, 2, 3], [2, 3, 1]); //=> true
```js
import { clone } from "@opentf/std";

await sleep(1000); // It suspends the exection for 1 second.
const obj = { a: 1, b: "abc", c: new Map([["key", "val"]]) };
console.log(clone(obj)); // Deeply cloned value
```

5. Checking Equality of Objects & Arrays:

```js
import { isEql, isEqlArr } from "@opentf/std";

const mapA = new Map([["a", 1], ["b", 2]]);
const mapB = new Map([["b", 2], ["a", 1]]);
console.log(isEql(mapA, mapB)); //=> false

console.log(isEqlArr([1, 2, 3], [2, 3, 1])); //=> true
```

6. Adding a Delay (1 second) with sleep:

```js
import { sleep } from "@opentf/std";

await sleep(1000); // Suspends execution for 1 second
```


<Callout type="default">

You can try out these examples on the [Playground](/playground).
Expand Down
72 changes: 50 additions & 22 deletions packages/std/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

## Installation

Install it using your favourite package manager.

```sh
npm install @opentf/std
```
Expand All @@ -44,31 +46,51 @@ pnpm add @opentf/std
bun add @opentf/std
```

```sh
deno add @opentf/std
```

## Usage

```ts
import {
isNum,
pascalCase,
sort,
clone,
isEql,
isEqlArr,
sleep,
} from '@opentf/std';
Let’s explore some of the library’s capabilities:

1. Checking if a Value is Numeric:

isNum(NaN); //=> false
```js
import { isNum } from '@opentf/std';

pascalCase('pascal case'); //=> PascalCase
console.log(isNum(NaN)); //=> false
```

sort([1, 10, 21, 2], 'desc'); //=> [ 21, 10, 2, 1 ]
2. Converting Strings to PascalCase:

const obj = {
a: 1,
b: 'abc',
c: new Map([['key', 'val']]),
};
clone(obj); // It returns deeply cloned value.
```js
import { pascalCase } from '@opentf/std';

console.log(pascalCase('pascal case')); //=> PascalCase
```

3. Sorting an Array in Descending Order:

```js
import { sort } from '@opentf/std';

console.log(sort([1, 10, 21, 2], 'desc')); //=> [21, 10, 2, 1]
```

4. Deep Cloning an Object:

```js
import { clone } from '@opentf/std';

const obj = { a: 1, b: 'abc', c: new Map([['key', 'val']]) };
console.log(clone(obj)); // Deeply cloned value
```

5. Checking Equality of Objects & Arrays:

```js
import { isEql, isEqlArr } from '@opentf/std';

const mapA = new Map([
['a', 1],
Expand All @@ -78,11 +100,17 @@ const mapB = new Map([
['b', 2],
['a', 1],
]);
isEql(mapA, mapB); //=> false
console.log(isEql(mapA, mapB)); //=> false

console.log(isEqlArr([1, 2, 3], [2, 3, 1])); //=> true
```

6. Adding a Delay (1 second) with sleep:

isEqlArr([1, 2, 3], [2, 3, 1]); //=> true
```js
import { sleep } from '@opentf/std';

await sleep(1000); // It suspends the exection for 1 second.
await sleep(1000); // Suspends execution for 1 second
```

## API
Expand Down
4 changes: 1 addition & 3 deletions packages/std/src/string/isEmail.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
function isEmail(str: string): boolean {
export default function isEmail(str: string): boolean {
const regex = new RegExp(
/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/
);
const result = regex.exec(str);

return result ? result[0] === str : false;
}

export default isEmail;

0 comments on commit 93dd23b

Please sign in to comment.