@fast-china/utils 1.0.13 → 1.0.14

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.
@@ -6,4 +6,8 @@ export declare const objectUtil: {
6
6
  * 对象URL参数化
7
7
  */
8
8
  objectToQueryString(obj: any): string;
9
+ /**
10
+ * 将外部传入的样式格式化成可读的 CSS 样式。
11
+ */
12
+ objectToStyle(styles: string | Record<string, any> | Record<string, any>[]): string;
9
13
  };
@@ -1,3 +1,5 @@
1
+ import { isArray, isString, isObject } from "lodash-unified";
2
+ import { stringUtil } from "../string/index.mjs";
1
3
  const objectUtil = {
2
4
  /**
3
5
  * 对象URL参数化
@@ -13,6 +15,29 @@ const objectUtil = {
13
15
  }
14
16
  }
15
17
  return params;
18
+ },
19
+ /**
20
+ * 将外部传入的样式格式化成可读的 CSS 样式。
21
+ */
22
+ objectToStyle(styles) {
23
+ if (isArray(styles)) {
24
+ return styles.filter(function(item) {
25
+ return item != null && item !== "";
26
+ }).map(function(item) {
27
+ return objectUtil.objectToStyle(item);
28
+ }).join(";");
29
+ }
30
+ if (isString(styles)) {
31
+ return styles;
32
+ }
33
+ if (isObject(styles)) {
34
+ return Object.keys(styles).filter(function(key) {
35
+ return styles[key] != null && styles[key] !== "";
36
+ }).map(function(key) {
37
+ return [stringUtil.toCamelCase(key), styles[key]].join(":");
38
+ }).join(";");
39
+ }
40
+ return "";
16
41
  }
17
42
  };
18
43
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/object/index.ts"],"sourcesContent":["/**\n * 对象工具类\n */\nexport const objectUtil = {\n\t/**\n\t * 对象URL参数化\n\t */\n\tobjectToQueryString(obj: any): string {\n\t\tlet params = \"\";\n\t\tfor (const key in obj) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(obj, key)) {\n\t\t\t\tif (params !== \"\") {\n\t\t\t\t\tparams += \"&\";\n\t\t\t\t}\n\t\t\t\tparams += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;\n\t\t\t}\n\t\t}\n\t\treturn params;\n\t},\n};\n"],"names":[],"mappings":"AAGO,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA,EAIzB,oBAAoB,KAAkB;AACrC,QAAI,SAAS;AACb,eAAW,OAAO,KAAK;AACtB,UAAI,OAAO,UAAU,eAAe,KAAK,KAAK,GAAG,GAAG;AACnD,YAAI,WAAW,IAAI;AACR,oBAAA;AAAA,QAAA;AAED,kBAAA,GAAG,mBAAmB,GAAG,CAAC,IAAI,mBAAmB,IAAI,GAAG,CAAC,CAAC;AAAA,MAAA;AAAA,IACrE;AAEM,WAAA;AAAA,EAAA;AAET;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/object/index.ts"],"sourcesContent":["import { isArray, isObject, isString } from \"lodash-unified\";\nimport { stringUtil } from \"../string\";\n\n/**\n * 对象工具类\n */\nexport const objectUtil = {\n\t/**\n\t * 对象URL参数化\n\t */\n\tobjectToQueryString(obj: any): string {\n\t\tlet params = \"\";\n\t\tfor (const key in obj) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(obj, key)) {\n\t\t\t\tif (params !== \"\") {\n\t\t\t\t\tparams += \"&\";\n\t\t\t\t}\n\t\t\t\tparams += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;\n\t\t\t}\n\t\t}\n\t\treturn params;\n\t},\n\t/**\n\t * 将外部传入的样式格式化成可读的 CSS 样式。\n\t */\n\tobjectToStyle(styles: string | Record<string, any> | Record<string, any>[]): string {\n\t\tif (isArray(styles)) {\n\t\t\treturn styles\n\t\t\t\t.filter(function (item) {\n\t\t\t\t\treturn item != null && item !== \"\";\n\t\t\t\t})\n\t\t\t\t.map(function (item) {\n\t\t\t\t\treturn objectUtil.objectToStyle(item);\n\t\t\t\t})\n\t\t\t\t.join(\";\");\n\t\t}\n\n\t\tif (isString(styles)) {\n\t\t\treturn styles;\n\t\t}\n\n\t\tif (isObject(styles)) {\n\t\t\treturn Object.keys(styles)\n\t\t\t\t.filter(function (key) {\n\t\t\t\t\treturn styles[key] != null && styles[key] !== \"\";\n\t\t\t\t})\n\t\t\t\t.map(function (key) {\n\t\t\t\t\treturn [stringUtil.toCamelCase(key), styles[key]].join(\":\");\n\t\t\t\t})\n\t\t\t\t.join(\";\");\n\t\t}\n\n\t\treturn \"\";\n\t},\n};\n"],"names":[],"mappings":";;AAMO,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA,EAIzB,oBAAoB,KAAkB;AACrC,QAAI,SAAS;AACb,eAAW,OAAO,KAAK;AACtB,UAAI,OAAO,UAAU,eAAe,KAAK,KAAK,GAAG,GAAG;AACnD,YAAI,WAAW,IAAI;AACR,oBAAA;AAAA,QAAA;AAED,kBAAA,GAAG,mBAAmB,GAAG,CAAC,IAAI,mBAAmB,IAAI,GAAG,CAAC,CAAC;AAAA,MAAA;AAAA,IACrE;AAEM,WAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAIA,cAAc,QAAsE;AAC/E,QAAA,QAAQ,MAAM,GAAG;AACb,aAAA,OACL,OAAO,SAAU,MAAM;AAChB,eAAA,QAAQ,QAAQ,SAAS;AAAA,MAAA,CAChC,EACA,IAAI,SAAU,MAAM;AACb,eAAA,WAAW,cAAc,IAAI;AAAA,MAAA,CACpC,EACA,KAAK,GAAG;AAAA,IAAA;AAGP,QAAA,SAAS,MAAM,GAAG;AACd,aAAA;AAAA,IAAA;AAGJ,QAAA,SAAS,MAAM,GAAG;AACrB,aAAO,OAAO,KAAK,MAAM,EACvB,OAAO,SAAU,KAAK;AACtB,eAAO,OAAO,GAAG,KAAK,QAAQ,OAAO,GAAG,MAAM;AAAA,MAAA,CAC9C,EACA,IAAI,SAAU,KAAK;AACZ,eAAA,CAAC,WAAW,YAAY,GAAG,GAAG,OAAO,GAAG,CAAC,EAAE,KAAK,GAAG;AAAA,MAAA,CAC1D,EACA,KAAK,GAAG;AAAA,IAAA;AAGJ,WAAA;AAAA,EAAA;AAET;"}
@@ -6,4 +6,8 @@ export declare const objectUtil: {
6
6
  * 对象URL参数化
7
7
  */
8
8
  objectToQueryString(obj: any): string;
9
+ /**
10
+ * 将外部传入的样式格式化成可读的 CSS 样式。
11
+ */
12
+ objectToStyle(styles: string | Record<string, any> | Record<string, any>[]): string;
9
13
  };
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={objectToQueryString(e){let t="";for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(""!==t&&(t+="&"),t+=`${encodeURIComponent(o)}=${encodeURIComponent(e[o])}`);return t}};exports.objectUtil=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("lodash-unified"),t=require("../string/index.js"),n={objectToQueryString(e){let t="";for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(""!==t&&(t+="&"),t+=`${encodeURIComponent(n)}=${encodeURIComponent(e[n])}`);return t},objectToStyle:o=>e.isArray(o)?o.filter((function(e){return null!=e&&""!==e})).map((function(e){return n.objectToStyle(e)})).join(";"):e.isString(o)?o:e.isObject(o)?Object.keys(o).filter((function(e){return null!=o[e]&&""!==o[e]})).map((function(e){return[t.stringUtil.toCamelCase(e),o[e]].join(":")})).join(";"):""};exports.objectUtil=n;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/object/index.ts"],"sourcesContent":["/**\n * 对象工具类\n */\nexport const objectUtil = {\n\t/**\n\t * 对象URL参数化\n\t */\n\tobjectToQueryString(obj: any): string {\n\t\tlet params = \"\";\n\t\tfor (const key in obj) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(obj, key)) {\n\t\t\t\tif (params !== \"\") {\n\t\t\t\t\tparams += \"&\";\n\t\t\t\t}\n\t\t\t\tparams += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;\n\t\t\t}\n\t\t}\n\t\treturn params;\n\t},\n};\n"],"names":["objectUtil","objectToQueryString","obj","params","key","Object","prototype","hasOwnProperty","call","encodeURIComponent"],"mappings":"gFAGO,MAAMA,EAAa,CAIzB,mBAAAC,CAAoBC,GACnB,IAAIC,EAAS,GACb,IAAA,MAAWC,KAAOF,EACbG,OAAOC,UAAUC,eAAeC,KAAKN,EAAKE,KAC9B,KAAXD,IACOA,GAAA,KAEDA,GAAA,GAAGM,mBAAmBL,MAAQK,mBAAmBP,EAAIE,OAG1D,OAAAD,CAAA"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/object/index.ts"],"sourcesContent":["import { isArray, isObject, isString } from \"lodash-unified\";\nimport { stringUtil } from \"../string\";\n\n/**\n * 对象工具类\n */\nexport const objectUtil = {\n\t/**\n\t * 对象URL参数化\n\t */\n\tobjectToQueryString(obj: any): string {\n\t\tlet params = \"\";\n\t\tfor (const key in obj) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(obj, key)) {\n\t\t\t\tif (params !== \"\") {\n\t\t\t\t\tparams += \"&\";\n\t\t\t\t}\n\t\t\t\tparams += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;\n\t\t\t}\n\t\t}\n\t\treturn params;\n\t},\n\t/**\n\t * 将外部传入的样式格式化成可读的 CSS 样式。\n\t */\n\tobjectToStyle(styles: string | Record<string, any> | Record<string, any>[]): string {\n\t\tif (isArray(styles)) {\n\t\t\treturn styles\n\t\t\t\t.filter(function (item) {\n\t\t\t\t\treturn item != null && item !== \"\";\n\t\t\t\t})\n\t\t\t\t.map(function (item) {\n\t\t\t\t\treturn objectUtil.objectToStyle(item);\n\t\t\t\t})\n\t\t\t\t.join(\";\");\n\t\t}\n\n\t\tif (isString(styles)) {\n\t\t\treturn styles;\n\t\t}\n\n\t\tif (isObject(styles)) {\n\t\t\treturn Object.keys(styles)\n\t\t\t\t.filter(function (key) {\n\t\t\t\t\treturn styles[key] != null && styles[key] !== \"\";\n\t\t\t\t})\n\t\t\t\t.map(function (key) {\n\t\t\t\t\treturn [stringUtil.toCamelCase(key), styles[key]].join(\":\");\n\t\t\t\t})\n\t\t\t\t.join(\";\");\n\t\t}\n\n\t\treturn \"\";\n\t},\n};\n"],"names":["objectUtil","objectToQueryString","obj","params","key","Object","prototype","hasOwnProperty","call","encodeURIComponent","objectToStyle","styles","isArray","filter","item","map","join","isString","isObject","keys","stringUtil","toCamelCase"],"mappings":"kJAMaA,EAAa,CAIzB,mBAAAC,CAAoBC,GACnB,IAAIC,EAAS,GACb,IAAA,MAAWC,KAAOF,EACbG,OAAOC,UAAUC,eAAeC,KAAKN,EAAKE,KAC9B,KAAXD,IACOA,GAAA,KAEDA,GAAA,GAAGM,mBAAmBL,MAAQK,mBAAmBP,EAAIE,OAG1D,OAAAD,CACR,EAIAO,cAAcC,GACTC,EAAAA,QAAQD,GACJA,EACLE,QAAO,SAAUC,GACV,OAAQ,MAARA,GAAyB,KAATA,CAAS,IAEhCC,KAAI,SAAUD,GACP,OAAAd,EAAWU,cAAcI,EAAI,IAEpCE,KAAK,KAGJC,EAAAA,SAASN,GACLA,EAGJO,EAAAA,SAASP,GACLN,OAAOc,KAAKR,GACjBE,QAAO,SAAUT,GACjB,OAAsB,MAAfO,EAAOP,IAAgC,KAAhBO,EAAOP,EAAS,IAE9CW,KAAI,SAAUX,GACP,MAAA,CAACgB,EAAAA,WAAWC,YAAYjB,GAAMO,EAAOP,IAAMY,KAAK,IAAG,IAE1DA,KAAK,KAGD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fast-china/utils",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Fast 工具库.",
5
5
  "type": "module",
6
6
  "keywords": [