antonmedv / antonmedv/tinysh

Specify an encoding?

Ouverte
#2 10 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
75
Forks
2
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

I love the idea behind this library!

How about implementing the Proxy like this:

```js
const {spawnSync} = require('child_process');
module.exports = new Proxy(
{},
{
get: (_, bin) => (...args) => {
return spawnSync(bin, args, {encoding: 'utf-8'});
},
}
)
```

A benefit of specifying an encoding is that you don’t need this code anymore: `Object.assign(new String(out.stdout), out)`

Are you using `{...this}` so that users can change the options of `spawnSync()`? Then I’d prefer a solution that doesn’t mutate a global object – maybe:

```js
function createShell(userOptions = {}) {
const options = {encoding: 'utf-8', ...userOptions};
return new Proxy(
{},
{
get: (_, bin) => (...args) => {
return spawnSync(bin, args, {encoding: 'utf-8'});
},
}
);
}

const sh = createShell();
console.log(sh.ls('-la'));
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.