open-index/open-npm huggingface dataset:
npm package: @sky0014/bind
Description: Bind all your class methods with one line.
Author: sky0014
Latest version: 1.0.4

# bind

Bind all your class methods with one line.

## Install

```bash
npm install @sky0014/bind
```

## Usage

```js
import { bindAll } from "@sky0014/bind";

class A {
  name = "A";

  constructor() {
    bindAll(this); // done, all your class methods have bind this already.
    // this.onclick = this.onclick.bind(this); // that's no need here
  }

  onclick() {
    console.log("hello", this.name); // this will always pointer to this A instance
  }
}
```
npm package: @sky0014/deep-merge
Description: Merge second object to first object just like Object.assign, best to use it with immer.
Author: sky0014
Latest version: 1.0.0

# deep-merge

Merge second object to first object just like Object.assign, best to use it with immer.

## Install

```bash
npm install @sky0014/deep-merge
```

## Usage

```ts
import produce from "immer";
import { deepMerge } from "@sky0014/deep-merge";

const a = { a: 1, b: 2, c: { hello: "world" } };

const b = produce(a, (draft) => {
  Object.assign(draft, { c: { hello: "world" } });
});

const c = produce(a, (draft) => {
  deepMerge(draft, { c: { hello: "world" } }); // equal to draft.c.hello = "world"
});

const d = produce(a, (draft) => {
  deepMerge(draft, { c: {} }); // d = { a: 1, b: 2, c: { } }
});

console.log(a === b); // false 内容未变，引用改变
console.log(a === c); // true  内容未变，引用未变
console.log(a === d); // false 内容改变，引用改变

const e = produce(a, (draft) => {
  return deepMerge(draft, { a: 1 }, true); // replace(NOT merge) draft
}); // e = { a: 1 }
```

## Publish

If your first time publish a package, login first:

```bash
npm login --registry=http://registry.npmjs.org
```

Then you can publish:

```bash
npm run pub
```
npm package: @sky0014/electron-ipc
Description: Make you use electron ipc call easier.
Author: sky0014
Latest version: 1.0.13

# electron-ipc

Make you use electron ipc call easier.

## Install

```bash
npm install @sky0014/electron-ipc
```

## Usage

In preload:

```ts
import "@sky0014/electron-ipc/preload";
```

In main:

```ts
// register main ipc
import { getIpcMain, registerIpcMain } from "@sky0014/electron-ipc/main";
import type { Renderer } from "./renderer";

const ipc = {
  filePick(options: OpenDialogOptions) {
    return dialog.showOpenDialog(options);
  },
};

registerIpcMain(ipc);

export type Main = typeof ipc;

// use ipc from renderer
getIpcMain<Renderer>().onShowMessage("hello world");
```

In renderer:

```ts
// register renderer ipc
import {
  getIpcRenderer,
  registerIpcRenderer,
} from "@sky0014/electron-ipc/renderer";
import type { Main } from "./main";

const ipc = {
  onShowMessage(data: Message) {
    // show message in ui
  },
};

registerIpcRenderer(ipc);

export type Renderer = typeof ipc;

// use ipc from main
getIpcRenderer<Main>().filePick(...);
```

## Publish

If your first time publish a package, login first:

```bash
npm login --registry=http://registry.npmjs.org
```

Then you can publish:

```bash
npm run pub
```
npm package: @sky0014/logger
Description: A simple logger for js
Author: sky0014
Latest version: 1.0.8

# logger

A simple logger for js.

## Install

```bash
npm install @sky0014/logger
```

## Usage

```js
import logger, { createLogger } from "@sky0014/logger";

// default logger, for most common use
logger.initLogger({
  enable: true,
  prefix: "easystore",
});

logger.log("hello there"); // [easystore] hello there

// isolated from default logger, for library use
const anotherLogger = createLogger();

anotherLogger.initLogger({
  enable: true,
  prefix: "another",
});

anotherLogger.log("hello there"); // [another] hello there
```

## Publish

If your first time publish a package, login first:

```bash
npm login --registry=https://registry.npmjs.org
```

Then you can publish:

```bash
npm run pub
```
npm package: @sky0014/serial
Description: A simple serialize library for js.
Author: sky0014
Latest version: 1.0.1

# serial

A simple serialize library for js.

## Install

```bash
npm install @sky0014/serial
```

## Usage

### Register class or funtions that need to be serialized (support nested)

```ts
import serial from "@sky0014/serial";

class A {
  _a = 1;

  get a() {
    return this._a;
  }

  set a(val: number) {
    this._a = val;
  }
}

class B {
  b = new A();
}

class C {
  c = {
    a: new A(),
    b: new B(),
    c: 2,
  };
}

serial.register({
  A,
  B,
  C,
});
```

### Serialize obj to string

```ts
import serial from "@sky0014/serial";

const str1 = serial.stringify(new A());
//'{"__@@serial_cls":{"__@@serial_type":"A","__@@serial_data":{"_a":1}}}'

const str2 = serial.stringify(new C());
// '{"__@@serial_cls":{"__@@serial_type":"C","__@@serial_data":{"c":{"a":{"__@@serial_cls":{"__@@serial_type":"A","__@@serial_data":{"_a":1}}},"b":{"__@@serial_cls":{"__@@serial_type":"B","__@@serial_data":{"b":{"__@@serial_cls":{"__@@serial_type":"A","__@@serial_data":{"_a":1}}}}}},"c":2}}}}'
```

### Parsed from string

```ts
const a = serial.parse(str1); // a instance of A
console.log(a._a); // 1
console.log(a.a); // 1

const c = serial.parse(str2);
// c instance of C
// c.c.a instance of A
// c.c.b instance of B
console.log(c.c.c); // 2
```

## Publish

If your first time publish a package, login first:

```bash
npm login --registry=https://registry.npmjs.org
```

Then you can publish:

```bash
npm run pub
```