Files
flipper/desktop/plugins/public/navigation/util/uri.tsx
Anton Nikolaev b3274a8450 Plugin folders re-structuring
Summary:
Here I'm changing plugin repository structure to allow re-using of shared packages between both public and fb-internal plugins, and to ensure that public plugins has their own yarn.lock as this will be required to implement reproducible jobs checking plugin compatibility with released flipper versions.

Please note that there are a lot of moved files in this diff, make sure to click "Expand all" to see all that actually changed (there are not much of them actually).

New proposed structure for plugin packages:
```
- root
- node_modules - modules included into Flipper: flipper, flipper-plugin, react, antd, emotion
-- plugins
 --- node_modules - modules used by both public and fb-internal plugins (shared libs will be linked here, see D27034936)
 --- public
---- node_modules - modules used by public plugins
---- pluginA
----- node_modules - modules used by plugin A exclusively
---- pluginB
----- node_modules - modules used by plugin B exclusively
 --- fb
---- node_modules - modules used by fb-internal plugins
---- pluginC
----- node_modules - modules used by plugin C exclusively
---- pluginD
----- node_modules - modules used by plugin D exclusively
```
I've moved all public plugins under dir "plugins/public" and excluded them from root yarn workspaces. Instead, they will have their own yarn workspaces config and yarn.lock and they will use flipper modules as peer dependencies.

Reviewed By: mweststrate

Differential Revision: D27034108

fbshipit-source-id: c2310e3c5bfe7526033f51b46c0ae40199fd7586
2021-04-09 05:22:00 -07:00

92 lines
2.5 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import querystring from 'querystring';
export const validateParameter = (value: string, parameter: string) => {
return (
value &&
(parameterIsNumberType(parameter) ? !isNaN(parseInt(value, 10)) : true) &&
(parameterIsBooleanType(parameter)
? value === 'true' || value === 'false'
: true)
);
};
export const filterOptionalParameters = (uri: string) => {
return uri.replace(/[/&]?([^&?={}\/]*=)?{\?.*?}/g, '');
};
export const parseURIParameters = (query: string) => {
// get parameters from query string and store in Map
const parameters = query.split('?').splice(1).join('');
const parametersObj = querystring.parse(parameters);
const parametersMap = new Map<string, string>();
for (const key in parametersObj) {
parametersMap.set(key, parametersObj[key] as string);
}
return parametersMap;
};
export const parameterIsNumberType = (parameter: string) => {
const regExp = /^{(#|\?#)/g;
return regExp.test(parameter);
};
export const parameterIsBooleanType = (parameter: string) => {
const regExp = /^{(!|\?!)/g;
return regExp.test(parameter);
};
export const replaceRequiredParametersWithValues = (
uri: string,
values: Array<string>,
) => {
const parameterRegExp = /{[^?]*?}/g;
const replaceRegExp = /{[^?]*?}/;
let newURI = uri;
let index = 0;
let match = parameterRegExp.exec(uri);
while (match != null) {
newURI = newURI.replace(replaceRegExp, values[index]);
match = parameterRegExp.exec(uri);
index++;
}
return newURI;
};
export const getRequiredParameters = (uri: string) => {
const parameterRegExp = /{[^?]*?}/g;
const matches: Array<string> = [];
let match = parameterRegExp.exec(uri);
while (match != null) {
if (match[0]) {
matches.push(match[0]);
}
match = parameterRegExp.exec(uri);
}
return matches;
};
export const liveEdit = (uri: string, formValues: Array<string>) => {
const parameterRegExp = /({[^?]*?})/g;
const uriArray = uri.split(parameterRegExp);
return uriArray.reduce((acc, uriComponent, idx) => {
if (idx % 2 === 0 || !formValues[(idx - 1) / 2]) {
return acc + uriComponent;
} else {
return acc + formValues[(idx - 1) / 2];
}
});
};
export const stripQueryParameters = (uri: string) => {
return uri.replace(/\?.*$/g, '');
};