Skip to content

Commit

Permalink
add helpers to lerna (PipedreamHQ#2052)
Browse files Browse the repository at this point in the history
  • Loading branch information
vellames authored Jan 13, 2022
1 parent 5141495 commit 9bc908e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
8 changes: 8 additions & 0 deletions helpers/index.mjs
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;

28 changes: 28 additions & 0 deletions helpers/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions helpers/package.json
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"
}
}
31 changes: 31 additions & 0 deletions helpers/sanitizedArray/index.mjs
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;
5 changes: 3 additions & 2 deletions lerna.json
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"
}

0 comments on commit 9bc908e

Please sign in to comment.