New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

string-mangle

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-mangle - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

48

index.js

@@ -0,1 +1,3 @@

const path = require("path");
const R = require("ramda");
function stringify(node, depth = 0) {

@@ -22,5 +24,49 @@ const indent = ' '.repeat(depth);

}
/**
* [Stringify file tree]
* @param {[type]} filesTree [description]
* @param {[type]} lazyLoad [description]
*/
function stringifyTree(filesTree){
return stringifyPattern('/', filesTree, 0);
}
/**
* @param {[type]} nodePath [description]
* @param {[type]} nodeValue [File tree object]
* @param {[type]} depth [description]
* @return {[type]} [description]
*/
function stringifyPattern(nodePath, nodeValue, depth) {
const indent = ' '.repeat(depth);
return R.cond([
[(n) => typeof n === 'object', (obj) => {
return `{\n${stringifyObject(nodePath, obj, depth)}\n${indent}}`;
}],
[R.T, (filename) => {
//We already get absolute filename
const filePath = path.join(process.cwd(), filename).split(path.sep).join("/");
return `require('${filePath}')`;
}]
])(nodeValue);
}
/**
* [stringify Object]
* @param {[type]} nodePath [description]
* @param {[type]} obj [description]
*/
function stringifyObject(nodePath, obj, depth) {
const indent = ' '.repeat(depth);
const kvStrings = R.pipe(
R.toPairs,
//R.toPairs({a: 1, b: 2, c: 3}); //=> [['a', 1], ['b', 2], ['c', 3]]
R.map((kv) =>
`${indent} '${kv[0]}': ${stringifyPattern(nodePath + '/' + kv[0], kv[1], depth + 1)}`)
)(obj);
return kvStrings.join('\n');
}
module.exports = {
stringify
stringify,
stringifyTree
}

7

package.json
{
"name": "string-mangle",
"version": "0.0.2",
"version": "0.0.3",
"description": "How to stringify an object or array",

@@ -25,3 +25,6 @@ "main": "index.js",

},
"homepage": "https://github.com/liangklfangl/string-mangle#readme"
"homepage": "https://github.com/liangklfangl/string-mangle#readme",
"dependencies": {
"ramda": "^0.23.0"
}
}

@@ -1,6 +0,6 @@

### Install
## Install
```js
$ npm install --save string-mangle
```
### Usage
## Usage
```js

@@ -22,1 +22,44 @@ const string = require('./index.js');

```
## API
(1)stringify:func(obj):
This method will stringify an object as above
(2)stringifyTree:func(fileTree)
This method will stringify an [file tree object](https://www.npmjs.com/package/grob-files).
Input is:
```js
const filetree = { filelists:
{ hello: 'filelists/hello.md',
index: 'filelists/index.md',
md:
{ fol: {
index: 'filelists/md/fol/index.md'
},
index: 'filelists/md/index.md'
}
}
}
```
Then you get something bellow returned:
```js
{
'filelists': {
'hello': require('C:/Users/Administrator/Desktop/string-mangle/filelists/hello.md')
'index': require('C:/Users/Administrator/Desktop/string-mangle/filelists/index.md')
'md': {
'fol': {
'index': require('C:/Users/Administrator/Desktop/string-mangle/filelists/md/fol/index.md')
}
'index': require('C:/Users/Administrator/Desktop/string-mangle/filelists/md/index.md')
}
}
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc