Skip to content

Commit

Permalink
add missing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nurliman committed May 8, 2024
1 parent 20e46cf commit b1fb7d6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-feet-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nurliman/base85": patch
---

add missing docs
4 changes: 3 additions & 1 deletion src/decode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Decodes a string from ASCII85
* @example
*
* ```ts
* import base85 from "@nurliman/base85";
*
* base85.decode('<~87cURD]i,"Ebo80~>');
Expand All @@ -9,6 +10,7 @@
* // it also works without the wrapping characters
* base85.decode('87cURD]i,"Ebo80');
* // output: Hello World!
* ```
*/
export function decodeBase85(input: string): string {
// Define constants and variables
Expand Down
6 changes: 5 additions & 1 deletion src/encode.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* `EncodeOptions` is an object that can be passed to the encode function to customize its behavior.
*/
export type EncodeOptions = {
/**
* If true, the encoded string will be wrapped in `<~` and `~>`.
Expand All @@ -12,15 +15,16 @@ export type EncodeOptions = {
* @param {Object} options Options for encoding
* @param {boolean} [options.wrap=true] If true, the encoded string will be wrapped in `<~` and `~>`. default is `true`
* @returns The encoded string
* @example
*
* ```ts
* import base85 from "@nurliman/base85";
*
* base85.encode("Hello World!");
* // output: <~87cURD]i,"Ebo80~>
*
* base85.encode("Hello World!", { wrap: false });
* // output: 87cURD]i,"Ebo80
* ```
*/
export function encodeBase85(input: string, { wrap = true }: EncodeOptions = {}): string {
if (!input) return wrap ? "<~~>" : "";
Expand Down
80 changes: 77 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,85 @@
/**
* `@nurliman/base85` is a Base85 encoder and decoder that compatible for Node.js and browser.
*
* ## Usage
*
* Import the package into your project:
*
* ```ts
* import { encodeBase85, decodeBase85 } from "@nurliman/base85";
*
* const encoded = encodeBase85("your string");
* const decoded = decodeBase85(encoded);
* ```
*
* using default import:
*
* ```ts
* import base85 from "@nurliman/base85";
*
* const encoded = base85.encode("your string");
* const decoded = base85.decode(encoded);
* ```
*
* using require:
*
* ```ts
* const { encodeBase85, decodeBase85 } = require("@nurliman/base85");
*
* const encoded = encodeBase85("your string");
* const decoded = decodeBase85(encoded);
* ```
*
* Please replace `'your string'` with the string you want to encode and decode.
*
* ### EncodeOptions
*
* `EncodeOptions` is an object that can be passed to the encode function to customize its behavior. It has the following properties:
*
* - `wrap`: If true, the encoded string will be wrapped in `<~` and `~>`. Defaults to `true`.
*
* Here's an example of how to use it:
*
* ```ts
* import base85 from "@nurliman/base85";
*
* const result = base85.encode("Hello World!");
* console.log(result);
* // <~87cURD]i,"Ebo80~>
*
* const result = base85.encode("Hello World!", {
* wrap: false, // Set this to false if you don't want the output to be wrapped
* });
* console.log(result);
* // 87cURD]i,"Ebo80
* ```
*
* ### Decode
*
* ```ts
* import base85 from "@nurliman/base85";
*
* const result = base85.decode('<~87cURD]i,"Ebo80~>');
* console.log(result);
* // Hello World!
*
* // it also works without the wrapping characters
* const result = base85.decode('87cURD]i,"Ebo80');
* console.log(result);
* // Hello World!
* ```
* @module
*/

import { decodeBase85 } from "./decode.ts";
import { encodeBase85 } from "./encode.ts";
export type * from "./encode.ts";
export { encodeBase85, decodeBase85 };

const base85 = {
/**
* Base85 encoder and decoder
*/
export default {
encode: encodeBase85,
decode: decodeBase85,
};

export default base85;

0 comments on commit b1fb7d6

Please sign in to comment.