@zhongguo168a/yxeditor-common 0.0.21 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1879,7 +1879,19 @@ declare class StringUtil {
1879
1879
  * @param source
1880
1880
  */
1881
1881
  evalFormat(format: string, source: any): string;
1882
- splitLast(val: string, separator: string): string;
1882
+ /**
1883
+ * 使用[separator]分割字符串,并替换掉在[index]位置的字符串
1884
+ * 如果没有发生变化,返回原来的值
1885
+ * @param val
1886
+ * @param separator
1887
+ * @param index
1888
+ * @param replace
1889
+ * @returns
1890
+ */
1891
+ replaceIndex(val: string, separator: string, index: number, replace?: string): string;
1892
+ splitIndex(val: string, separator: string, index: number, dflt?: string): string;
1893
+ splitFirst(val: string, separator: string, dflt?: string): string;
1894
+ splitLast(val: string, separator: string, dflt?: string): string;
1883
1895
  /**
1884
1896
  * 从最后一个分隔符截断字符串,返回截断的左右字符串
1885
1897
  * @param val
package/dist/index.esm.js CHANGED
@@ -5927,12 +5927,43 @@ class StringUtil {
5927
5927
  }
5928
5928
  return result;
5929
5929
  }
5930
- splitLast(val, separator) {
5930
+ /**
5931
+ * 使用[separator]分割字符串,并替换掉在[index]位置的字符串
5932
+ * 如果没有发生变化,返回原来的值
5933
+ * @param val
5934
+ * @param separator
5935
+ * @param index
5936
+ * @param replace
5937
+ * @returns
5938
+ */
5939
+ replaceIndex(val, separator, index, replace = "") {
5940
+ let arr = val.split(separator);
5941
+ if (arr.length > index) {
5942
+ arr[index] = replace;
5943
+ return arr.join(separator);
5944
+ }
5945
+ return val;
5946
+ }
5947
+ splitIndex(val, separator, index, dflt = "") {
5948
+ let arr = val.split(separator);
5949
+ if (arr.length > index) {
5950
+ return arr[index];
5951
+ }
5952
+ return dflt;
5953
+ }
5954
+ splitFirst(val, separator, dflt = "") {
5955
+ let arr = val.split(separator);
5956
+ if (arr.length > 0) {
5957
+ return arr[0];
5958
+ }
5959
+ return dflt;
5960
+ }
5961
+ splitLast(val, separator, dflt = "") {
5931
5962
  let arr = val.split(separator);
5932
5963
  if (arr.length > 0) {
5933
5964
  return arr[arr.length - 1];
5934
5965
  }
5935
- return val;
5966
+ return dflt;
5936
5967
  }
5937
5968
  /**
5938
5969
  * 从最后一个分隔符截断字符串,返回截断的左右字符串