|
|
@@ -1,15 +1,14 @@
|
|
|
-import { isString, isArray } from 'lodash-es';
|
|
|
+import { isString, isArray, isNumber } from 'lodash-es';
|
|
|
|
|
|
/**
|
|
|
- * Get the splited array
|
|
|
- * @param {string} originString String to be splited
|
|
|
- * @param {string | string[]} separators
|
|
|
- * @returns {string[]} The splited result array
|
|
|
+ * Get the splited array.
|
|
|
+ * We expect separators to be string | string[] | null, but users
|
|
|
+ * are also allowed to pass in other types.
|
|
|
*/
|
|
|
-const getSplitedArray = (originString: string, separators: string | string[]) => {
|
|
|
+const getSplitedArray = (originString: string, separators: string | string[] | null) => {
|
|
|
let splitedValue: string | string[] = [];
|
|
|
- if (isString(separators)) {
|
|
|
- splitedValue = originString.split(separators);
|
|
|
+ if (isString(separators) || isNumber(separators)) {
|
|
|
+ splitedValue = originString.split(separators as string);
|
|
|
} else if (isArray(separators)) {
|
|
|
const tempChar = separators[0]; // temporary splitter
|
|
|
splitedValue = originString;
|
|
|
@@ -17,6 +16,8 @@ const getSplitedArray = (originString: string, separators: string | string[]) =>
|
|
|
splitedValue = splitedValue.split(separators[i]).join(tempChar);
|
|
|
}
|
|
|
splitedValue = splitedValue.split(tempChar);
|
|
|
+ } else {
|
|
|
+ splitedValue.push(originString);
|
|
|
}
|
|
|
return splitedValue;
|
|
|
};
|