Giter Site home page Giter Site logo

jimmycuadra / shellwords Goto Github PK

View Code? Open in Web Editor NEW
38.0 4.0 5.0 83 KB

Manipulate strings according to the word parsing rules of the UNIX Bourne shell.

Home Page: https://www.npmjs.com/package/shellwords

License: MIT License

JavaScript 13.09% HTML 5.58% TypeScript 79.84% Shell 1.48%
shellwords shell nodejs javascript typescript esm esmodules esmodule commonjs commonjs-modules

shellwords's Introduction

Shellwords

Shellwords provides functions to manipulate strings according to the word parsing rules of the UNIX Bourne shell. It is based on the Ruby module of the same name.

Installation

With npm:

npm install shellwords

With pnpm:

pnpm add shellwords

With Yarn:

yarn add shellwords

API

Shellwords exports the following functions, shown here in the TypeScript declaration file format.

/**
 * Splits a string into an array of tokens in the same way the UNIX Bourne shell does.
 *
 * @param line A string to split.
 * @returns An array of the split tokens.
 */
export declare const split: (line?: string) => string[];

/**
 * Escapes a string so that it can be safely used in a Bourne shell command line.
 *
 * @param str A string to escape.
 * @returns The escaped string.
 */
export declare const escape: (str?: string) => string;

Example

import { escape, split } from "shellwords";

split("foo 'bar baz'");
// ["foo", "bar baz"]

escape("What's up, yo?");
// 'What\\\'s\\ up,\\ yo\\?'

Legal

shellwords is released under the MIT license. See LICENSE.

shellwords's People

Contributors

annamatveev avatar ixti avatar jimmycuadra avatar wtgtybhertgeghgtwtg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

shellwords's Issues

Lose slash on windows

var command = '"D:\work\arduino\git\ml_agent\avrdude/bin/avrdude" "-CD:\work\arduino\git\ml_agent\avrdude/etc/avrdude.conf" -v -patmega328p -carduino -PCOM7 -b115200 -D "-Uflash:w:D:\work\arduino\git\ml_agent\tmp/code.ino.hex:i"'
var args = shellwords.split(command);
args:
[ 'D:work\arduino\git\ml_agent\avrdude/bin/avrdude',
'-CD:work\arduino\git\ml_agent\avrdude/etc/avrdude.conf',
'-v',
'-patmega328p',
'-carduino',
'-PCOM7',
'-b115200',
'-D',
'-Uflash:w:D:work\arduino\git\ml_agent\tmp/code.ino.hex:i' ]

all the path lost the slash...

Windows compatibility

๐Ÿ‘‹ Hi there, we're using shellwords in@effection/node and it's been really great so far. I noticed that the last major change to this was eight years ago. Amazing how software can keep going and going!

https://github.com/thefrontside/effection/blob/v0/packages/node/src/exec.ts#L18

Anyhow, we're looking to add Windows support to this library and noticed that shellwords, when splitting a command on windows removes all \ characters which is the path separator on windows. So, for example:

\Users\cowboyd\Code\bigtest\node_modules\.bin\ts-node is converted to UserscowboydCodebigtestnode_modules.bints-node`

I'd be happy to submit a PR to fix this if you'd be willing to release it. Alternatively, we'd also be happy to take over maintenance of this repository and npm package if you'd be willing to donate it. Let me know and thanks again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.