diff options
author | Ali Hasani <a.hassssani@gmail.com> | 2020-04-24 22:54:29 +0430 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-24 14:24:29 -0400 |
commit | 6efdacddf30b5247b66596a44226687ff21a8f80 (patch) | |
tree | 23c9407a3db422dcb1dc3a0cdb969eec75f6e78c /std/bytes/README.md | |
parent | 0da042c6fe067996e09f5c544502534b14b48713 (diff) |
create readme for std/bytes (#4876)
Diffstat (limited to 'std/bytes/README.md')
-rw-r--r-- | std/bytes/README.md | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/std/bytes/README.md b/std/bytes/README.md new file mode 100644 index 000000000..bf0fcc5b0 --- /dev/null +++ b/std/bytes/README.md @@ -0,0 +1,79 @@ +# bytes + +bytes module is made to provide helpers to manipulation of bytes slice. + +# usage + +All the following functions are exposed in `mod.ts` + +## findIndex + +Find first index of binary pattern from given binary array. + +```typescript +import { findIndex } from "https://deno.land/std/bytes/mod.ts"; + +findIndex( + new Uint8Array([1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 3]), + new Uint8Array([0, 1, 2]) +); + +// => returns 2 +``` + +## findLastIndex + +Find last index of binary pattern from given binary array. + +```typescript +import { findLastIndex } from "https://deno.land/std/bytes/mod.ts"; + +findLastIndex( + new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1, 3]), + new Uint8Array([0, 1, 2]) +); + +// => returns 3 +``` + +## equal + +Check whether given binary arrays are equal to each other. + +```typescript +import { equal } from "https://deno.land/std/bytes/mod.ts"; + +equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 3])); // returns true +equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 4])); // returns false +``` + +## hasPrefix + +Check whether binary array has binary prefix. + +```typescript +import { hasPrefix } from "https://deno.land/std/bytes/mod.ts"; + +hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([0, 1])); // returns true +hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([1, 2])); // returns false +``` + +## repeat + +Repeat bytes of given binary array and return new one. + +```typescript +import { repeat } from "https://deno.land/std/bytes/mod.ts"; + +repeat(new Uint8Array([1]), 3); // returns Uint8Array(3) [ 1, 1, 1 ] +``` + +## concat + +Concatenate two binary arrays and return new one. + +```typescript +import { concat } from "https://deno.land/std/bytes/mod.ts"; + +concat(new Uint8Array([1, 2]), new Uint8Array([3, 4])); // returns Uint8Array(4) [ 1, 2, 3, 4 ] +``` |