Common operations with strings, which can be used in your command line and code.
npm install cli-string
npm install -g cli-string
`
or
`
npm i -g cli-string
`
Usage
$3
To list all commands:
`shell
$ cstr help
`
To run command with the full name:
`shell
$ cli-string [options]
`
Or shortened alias:
`shell
$ cstr [options]
`
$3
you can also use the library in your code:
`typescript
import { jsonPretty } from 'cli-string';
const prettyJson = jsonPretty('{"thisIs": "JSON"}', 4);
/**
* {
* "thisIs": "JSON"
* }
*/
`
Commands
$3
Makes your ugly JSON string pretty with specified spaces amount
`shell
USAGE
$ cstr jsonPretty [--spaces ]
OPTIONS
--spaces 2 # Number of spaces for tabulation. Can't be less than 2, default: 2
EXAMPLE
$ cstr jsonPretty --spaces 4 "{\"test\":\"JSON\"}"
# {
# "test": "JSON"
# }
`
$3
Encodes given string in specific format
`shell
USAGE
$ cstr encode
FORMATS
- base64
- base64url
- ascii
- binary
- hex
- utf16le
EXAMPLE
$ cstr encode base64 "This is my string"
# VGhpcyBpcyBteSBzdHJpbmc=
`
$3
Decodes given string from specific format to UTF-8 string
`shell
USAGE
$ cstr decode
FORMATS
- base64
- base64url
- ascii
- binary
- hex
- utf16le
EXAMPLE
$ cstr decode base64 VGhpcyBpcyBteSBzdHJpbmc=
# This is my string
`
$3
Hashes string in specified format
`shell
USAGE
$ cstr hash
FORMATS
- md5
- sha1
- sha256
- sha224
- sha512
- sha384
- sha3
- ripemd160
EXAMPLE
$ cstr hash sha256 "This is my string"
# 9da6c02379110815278b615f015f0b254fd3d5a691c9d8abf8141655982c046b
`
$3
Quote string with slashes
`shell
USAGE
$ cstr addslashes
EXAMPLE
$ cstr addslashes "O'Reilly?"
# O\'Reilly?
`
$3
Un-quotes a quoted string
`shell
USAGE
$ cstr stripslashes
EXAMPLE
$ cstr stripslashes "O\'Reilly?"
# O'Reilly?
`
$3
Encodes the special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #
`shell
USAGE
$ cstr encodeUrl
EXAMPLE
$ cstr encodeUrl "https://this.is/my?=url"
# https%3A%2F%2Fthis.is%2Fmy%3F%3Durl
`
$3
Decodes URL generated by encodeUrl
`shell
USAGE
$ cstr decodeUrl
EXAMPLE
$ cstr decodeUrl "https%3A%2F%2Fthis.is%2Fmy%3F%3Durl"
# https://this.is/my?=url
`
Tips and Tricks
$3
You can curl url content, prettify it and save to the file:
`shell
$ curl https://www.boredapi.com/api/activity | xargs -t -0 ./dist/cli.js jsonPretty > test.txt
`
This will create a test.txt file with content like this:
`json
{
"activity": "Write a short story",
"type": "recreational",
"participants": 1,
"price": 0,
"link": "",
"key": "6301585",
"accessibility": 0.1
}
``