tinyscripts
Advanced tools
Comparing version 2.0.0 to 2.0.1
48
index.js
@@ -1,37 +0,15 @@ | ||
exports.base64 = function(type, text) { | ||
if (!(type == 'encode' || type == 'decode')) throw new TypeError('You must specify encode or decode'); | ||
if (!type) throw new TypeError(`You must specify text to ${type}`); | ||
const { encode, decode, validate } = require('./functions/base64'); | ||
const { camelCase } = require('./functions/camelCase'); | ||
const { translate, CharMap } = require('./functions/translate'); | ||
const { isUpperCase, isLowerCase } = require('./functions/case'); | ||
function encode(text) { | ||
let buff = new Buffer.from(text); | ||
let base64data = buff.toString('base64'); | ||
let res = { | ||
originalData: text, | ||
buff: buff, | ||
base64: base64data | ||
}; | ||
return res; | ||
} | ||
function decode(text) { | ||
let buff = new Buffer.from(text, 'base64'); | ||
let base64data = buff.toString('ascii'); | ||
let res = { | ||
originalData: text, | ||
buff: buff, | ||
base64: base64data | ||
}; | ||
return res; | ||
} | ||
try { | ||
if (type == 'encode') { | ||
let res = encode(text); | ||
return res.base64; | ||
} else { | ||
let res = decode(text); | ||
return res.base64; | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
module.exports = { | ||
base64: { | ||
encode, | ||
decode, | ||
validate | ||
}, | ||
camelCase, | ||
translate, | ||
CharMap | ||
}; |
{ | ||
"name": "tinyscripts", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Tiny Useful Scripts", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test.js" | ||
}, | ||
"repository": { | ||
@@ -7,0 +10,0 @@ "type": "git", |
@@ -1,7 +0,70 @@ | ||
# TinyScripts | ||
<h1 align="center"><a href="https://www.npmjs.com/package/tinyscripts" target="_blank"> TinyScripts </a></h1> | ||
<h2 align="center"> A tiny set of scripts designed for quick access. </h2> | ||
<br> | ||
<div align="center"> | ||
### A set of small scripts | ||
[![npm](https://img.shields.io/npm/v/tinyscripts)](https://www.npmjs.com/package/tinyscripts) | ||
[![npm size](https://img.shields.io/bundlephobia/min/tinyscripts)](https://www.npmjs.com/package/tinyscripts) | ||
</div> | ||
## Install | ||
``` | ||
npm i tinyscripts | ||
``` | ||
<br> | ||
## Usage | ||
### base64 | ||
```js | ||
const { base64 } = require('tinyscripts'); | ||
var encoded = base64.encode('Hello World'); | ||
//=> SGVsbG8gV29ybGQ= | ||
base64.decode(encoded); | ||
//=> Hello World | ||
base64.validate(encoded) | ||
//=> true | ||
``` | ||
- **base64.encode(str)** - Encodes "str" with base64 | ||
- **base64.decode(base64)** - Decodes "str" from base64 | ||
- **base64.validate(base64)** - Validates "str" to see if it is valid base64 | ||
### camelCase | ||
```js | ||
const { camelCase } = require('tinyscripts'); | ||
camelCase('make this camel case') | ||
//=> makeThisCamelCase | ||
``` | ||
- **camelCase(str)** - Turns "str" into camel case format | ||
### charMap & translate | ||
```js | ||
const { charMap, translate } = require('tinyscripts'); | ||
var map = new CharMap('hwo', 'uey'); | ||
var translation = translate('Hello World', map); | ||
//=> Uelly Eyrld | ||
``` | ||
- **charMap(from, to)** - Creates a new charMap that can be used with translate() [(More Info)](#charMap) | ||
- **translate(str, map)** - Translates a string based on a charMap. This is similar to the [python translate()](https://www.w3schools.com/python/ref_string_translate.asp) function. | ||
### isUpperCase & isLowerCase | ||
```js | ||
const { isUpperCase, isLowerCase } = require('tinyscripts'); | ||
isUpperCase('C') | ||
//=> true | ||
isUpperCase('c') | ||
//=> false | ||
isLowerCase('c') | ||
//=> true | ||
``` | ||
- **isUpperCase(str)** - Returns true or false depending on if the string is uppercase. | ||
- **isLowerCase(str)** - Returns true or false depending on if the string is lowercase. | ||
## More Info | ||
### charMap | ||
charMaps can be used with translate() to replace a charactar in a string with one of another. This is similar to the [python translate()](https://www.w3schools.com/python/ref_string_translate.asp) function. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6058
7
84
71