forked from PipedreamHQ/pipedream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helpers to lerna (PipedreamHQ#2052)
- Loading branch information
Showing
5 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import sanitizedArray from "./sanitizedArray/index.mjs"; | ||
|
||
export const helpers = { | ||
sanitizedArray, | ||
}; | ||
|
||
export default helpers; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@pipedream/helpers", | ||
"version": "0.0.1", | ||
"description": "Pipedream Component Helpers", | ||
"main": "index.js", | ||
"keywords": [ | ||
"pipedream" | ||
], | ||
"homepage": "https://pipedream.com/", | ||
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"lodash.get": "^4.4.2", | ||
"lodash.isarray": "^4.0.0", | ||
"lodash.isempty": "^4.4.0", | ||
"lodash.isstring": "^4.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import isArray from "lodash/isArray.js"; | ||
import get from "lodash/get.js"; | ||
import isString from "lodash/isString.js"; | ||
import isEmpty from "lodash/isEmpty.js"; | ||
|
||
export const sanitizedArray = (value) => { | ||
if (isArray(value)) { | ||
return value.map((item) => get(item, "value", item)); | ||
} | ||
|
||
// If is string, try to convert it in an array | ||
if (isString(value)) { | ||
// Return an empty array if string is empty | ||
if (isEmpty(value)) { | ||
return []; | ||
} | ||
|
||
return value | ||
// Remove square brackets from ends ([ "foo", 5 ] -> "foo", 5 ) | ||
.replace(/(^\[)|(]$)/g, "") | ||
.trim() // ( "foo", 5 -> "foo", 5) | ||
// Remove quotes from ends ("foo", 5 -> foo", 5) | ||
.replace(/^["']|["']$/g, "") | ||
// Split on quotes, whitespace, and comma (foo", 5 -> ["foo","5"]) | ||
.split(/["']?\s*,\s*["']?/); | ||
} | ||
|
||
throw new Error(`${value} is not an array or an array-like`); | ||
}; | ||
|
||
export default sanitizedArray; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"packages": [ | ||
"components/*", | ||
"interfaces/*" | ||
"interfaces/*", | ||
"helpers/*" | ||
], | ||
"version": "0.3.3" | ||
"version": "0.3.4" | ||
} |