@fast-china/utils 1.0.19 → 1.0.21

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/es/dom/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { addUnit } from "./style.mjs";
1
+ import { addUnit, styleToString } from "./style.mjs";
2
2
  export {
3
- addUnit
3
+ addUnit,
4
+ styleToString
4
5
  };
5
6
  //# sourceMappingURL=index.mjs.map
package/es/dom/style.d.ts CHANGED
@@ -4,3 +4,9 @@
4
4
  * @param defaultUnit 单位
5
5
  */
6
6
  export declare const addUnit: (value?: string | number, defaultUnit?: string) => string;
7
+ /**
8
+ * 将样式对象转换为内联 style 字符串(kebab-case 格式)
9
+ * @param style 样式对象(CSSStyleDeclaration)
10
+ * @returns 返回符合 HTML 内联格式的样式字符串,例如 "font-size: 14px; color: red;"
11
+ */
12
+ export declare const styleToString: (style: Partial<CSSStyleDeclaration>) => string;
package/es/dom/style.mjs CHANGED
@@ -15,7 +15,15 @@ const addUnit = (value, defaultUnit = "px") => {
15
15
  }
16
16
  consoleWarn("document", "binding value must be a string or number");
17
17
  };
18
+ const styleToString = (style) => {
19
+ if (!style) return "";
20
+ return Object.entries(style).map(([key, value]) => {
21
+ const keyName = key.replace(/([A-Z])/g, "-$1").toLowerCase();
22
+ return `${keyName}: ${value};`;
23
+ }).join(" ");
24
+ };
18
25
  export {
19
- addUnit
26
+ addUnit,
27
+ styleToString
20
28
  };
21
29
  //# sourceMappingURL=style.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"style.mjs","sources":["../../../../src/dom/style.ts"],"sourcesContent":["import { isNumber, isString } from \"lodash-unified\";\nimport { consoleWarn } from \"../console\";\n\nconst isStringNumber = (val: string): boolean => {\n\tif (!isString(val)) {\n\t\treturn false;\n\t}\n\treturn !Number.isNaN(Number(val));\n};\n\n/**\n * 添加单位\n * @param value 字符串或数字类型\n * @param defaultUnit 单位\n */\nexport const addUnit = (value?: string | number, defaultUnit = \"px\"): string => {\n\tif (!value) return \"\";\n\tif (isNumber(value) || isStringNumber(value)) {\n\t\treturn `${value}${defaultUnit}`;\n\t} else if (isString(value)) {\n\t\treturn value;\n\t}\n\tconsoleWarn(\"document\", \"binding value must be a string or number\");\n};\n"],"names":[],"mappings":";;AAGA,MAAM,iBAAiB,CAAC,QAAyB;AAC5C,MAAA,CAAC,SAAS,GAAG,GAAG;AACZ,WAAA;AAAA,EAAA;AAER,SAAO,CAAC,OAAO,MAAM,OAAO,GAAG,CAAC;AACjC;AAOO,MAAM,UAAU,CAAC,OAAyB,cAAc,SAAiB;AAC3E,MAAA,CAAC,MAAc,QAAA;AACnB,MAAI,SAAS,KAAK,KAAK,eAAe,KAAK,GAAG;AACtC,WAAA,GAAG,KAAK,GAAG,WAAW;AAAA,EAAA,WACnB,SAAS,KAAK,GAAG;AACpB,WAAA;AAAA,EAAA;AAER,cAAY,YAAY,0CAA0C;AACnE;"}
1
+ {"version":3,"file":"style.mjs","sources":["../../../../src/dom/style.ts"],"sourcesContent":["import { isNumber, isString } from \"lodash-unified\";\nimport { consoleWarn } from \"../console\";\n\nconst isStringNumber = (val: string): boolean => {\n\tif (!isString(val)) {\n\t\treturn false;\n\t}\n\treturn !Number.isNaN(Number(val));\n};\n\n/**\n * 添加单位\n * @param value 字符串或数字类型\n * @param defaultUnit 单位\n */\nexport const addUnit = (value?: string | number, defaultUnit = \"px\"): string => {\n\tif (!value) return \"\";\n\tif (isNumber(value) || isStringNumber(value)) {\n\t\treturn `${value}${defaultUnit}`;\n\t} else if (isString(value)) {\n\t\treturn value;\n\t}\n\tconsoleWarn(\"document\", \"binding value must be a string or number\");\n};\n\n/**\n * 将样式对象转换为内联 style 字符串(kebab-case 格式)\n * @param style 样式对象(CSSStyleDeclaration)\n * @returns 返回符合 HTML 内联格式的样式字符串,例如 \"font-size: 14px; color: red;\"\n */\nexport const styleToString = (style: Partial<CSSStyleDeclaration>): string => {\n\tif (!style) return \"\";\n\treturn Object.entries(style)\n\t\t.map(([key, value]) => {\n\t\t\tconst keyName = key.replace(/([A-Z])/g, \"-$1\").toLowerCase();\n\t\t\treturn `${keyName}: ${value};`;\n\t\t})\n\t\t.join(\" \");\n};\n"],"names":[],"mappings":";;AAGA,MAAM,iBAAiB,CAAC,QAAyB;AAC5C,MAAA,CAAC,SAAS,GAAG,GAAG;AACZ,WAAA;AAAA,EAAA;AAER,SAAO,CAAC,OAAO,MAAM,OAAO,GAAG,CAAC;AACjC;AAOO,MAAM,UAAU,CAAC,OAAyB,cAAc,SAAiB;AAC3E,MAAA,CAAC,MAAc,QAAA;AACnB,MAAI,SAAS,KAAK,KAAK,eAAe,KAAK,GAAG;AACtC,WAAA,GAAG,KAAK,GAAG,WAAW;AAAA,EAAA,WACnB,SAAS,KAAK,GAAG;AACpB,WAAA;AAAA,EAAA;AAER,cAAY,YAAY,0CAA0C;AACnE;AAOa,MAAA,gBAAgB,CAAC,UAAgD;AACzE,MAAA,CAAC,MAAc,QAAA;AACZ,SAAA,OAAO,QAAQ,KAAK,EACzB,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACtB,UAAM,UAAU,IAAI,QAAQ,YAAY,KAAK,EAAE,YAAY;AACpD,WAAA,GAAG,OAAO,KAAK,KAAK;AAAA,EAAA,CAC3B,EACA,KAAK,GAAG;AACX;"}
package/es/index.mjs CHANGED
@@ -13,7 +13,7 @@ import { objectUtil } from "./object/index.mjs";
13
13
  import { CACHE_EXPIRE_SUFFIX, CACHE_PREFIX, Local, Session, useStorage } from "./storage/index.mjs";
14
14
  import { stringUtil } from "./string/index.mjs";
15
15
  import "./vue/index.mjs";
16
- import { addUnit } from "./dom/style.mjs";
16
+ import { addUnit, styleToString } from "./dom/style.mjs";
17
17
  import { useExpose } from "./vue/expose.mjs";
18
18
  import { execFunction } from "./vue/func.mjs";
19
19
  import { withInstall, withInstallDirective, withNoopInstall } from "./vue/install.mjs";
@@ -44,6 +44,7 @@ export {
44
44
  makeSlots,
45
45
  objectUtil,
46
46
  stringUtil,
47
+ styleToString,
47
48
  throwError,
48
49
  useExpose,
49
50
  useIdentity,
package/lib/dom/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./style.js");exports.addUnit=e.addUnit;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./style.js");exports.addUnit=t.addUnit,exports.styleToString=t.styleToString;
2
2
  //# sourceMappingURL=index.js.map
@@ -4,3 +4,9 @@
4
4
  * @param defaultUnit 单位
5
5
  */
6
6
  export declare const addUnit: (value?: string | number, defaultUnit?: string) => string;
7
+ /**
8
+ * 将样式对象转换为内联 style 字符串(kebab-case 格式)
9
+ * @param style 样式对象(CSSStyleDeclaration)
10
+ * @returns 返回符合 HTML 内联格式的样式字符串,例如 "font-size: 14px; color: red;"
11
+ */
12
+ export declare const styleToString: (style: Partial<CSSStyleDeclaration>) => string;
package/lib/dom/style.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("lodash-unified"),r=require("../console/index.js");exports.addUnit=(i,n="px")=>{return i?e.isNumber(i)||(t=i,e.isString(t)&&!Number.isNaN(Number(t)))?`${i}${n}`:e.isString(i)?i:void r.consoleWarn("document","binding value must be a string or number"):"";var t};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("lodash-unified"),r=require("../console/index.js");exports.addUnit=(i,t="px")=>{return i?e.isNumber(i)||(n=i,e.isString(n)&&!Number.isNaN(Number(n)))?`${i}${t}`:e.isString(i)?i:void r.consoleWarn("document","binding value must be a string or number"):"";var n},exports.styleToString=e=>e?Object.entries(e).map((([e,r])=>`${e.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${r};`)).join(" "):"";
2
2
  //# sourceMappingURL=style.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"style.js","sources":["../../../../src/dom/style.ts"],"sourcesContent":["import { isNumber, isString } from \"lodash-unified\";\nimport { consoleWarn } from \"../console\";\n\nconst isStringNumber = (val: string): boolean => {\n\tif (!isString(val)) {\n\t\treturn false;\n\t}\n\treturn !Number.isNaN(Number(val));\n};\n\n/**\n * 添加单位\n * @param value 字符串或数字类型\n * @param defaultUnit 单位\n */\nexport const addUnit = (value?: string | number, defaultUnit = \"px\"): string => {\n\tif (!value) return \"\";\n\tif (isNumber(value) || isStringNumber(value)) {\n\t\treturn `${value}${defaultUnit}`;\n\t} else if (isString(value)) {\n\t\treturn value;\n\t}\n\tconsoleWarn(\"document\", \"binding value must be a string or number\");\n};\n"],"names":["value","defaultUnit","isNumber","val","isString","Number","isNaN","index","consoleWarn"],"mappings":"mKAeuB,CAACA,EAAyBC,EAAc,QAC1D,OAACD,EACDE,EAASA,SAAAF,KAdUG,EAceH,EAbjCI,EAAAA,SAASD,KAGNE,OAAOC,MAAMD,OAAOF,KAWpB,GAAGH,IAAQC,IACRG,EAAAA,SAASJ,GACZA,OAERO,EAAAC,YAAY,WAAY,4CANL,GAbG,IAACL,CAmB2C"}
1
+ {"version":3,"file":"style.js","sources":["../../../../src/dom/style.ts"],"sourcesContent":["import { isNumber, isString } from \"lodash-unified\";\nimport { consoleWarn } from \"../console\";\n\nconst isStringNumber = (val: string): boolean => {\n\tif (!isString(val)) {\n\t\treturn false;\n\t}\n\treturn !Number.isNaN(Number(val));\n};\n\n/**\n * 添加单位\n * @param value 字符串或数字类型\n * @param defaultUnit 单位\n */\nexport const addUnit = (value?: string | number, defaultUnit = \"px\"): string => {\n\tif (!value) return \"\";\n\tif (isNumber(value) || isStringNumber(value)) {\n\t\treturn `${value}${defaultUnit}`;\n\t} else if (isString(value)) {\n\t\treturn value;\n\t}\n\tconsoleWarn(\"document\", \"binding value must be a string or number\");\n};\n\n/**\n * 将样式对象转换为内联 style 字符串(kebab-case 格式)\n * @param style 样式对象(CSSStyleDeclaration)\n * @returns 返回符合 HTML 内联格式的样式字符串,例如 \"font-size: 14px; color: red;\"\n */\nexport const styleToString = (style: Partial<CSSStyleDeclaration>): string => {\n\tif (!style) return \"\";\n\treturn Object.entries(style)\n\t\t.map(([key, value]) => {\n\t\t\tconst keyName = key.replace(/([A-Z])/g, \"-$1\").toLowerCase();\n\t\t\treturn `${keyName}: ${value};`;\n\t\t})\n\t\t.join(\" \");\n};\n"],"names":["value","defaultUnit","isNumber","val","isString","Number","isNaN","index","consoleWarn","style","Object","entries","map","key","replace","toLowerCase","join"],"mappings":"mKAeuB,CAACA,EAAyBC,EAAc,QAC1D,OAACD,EACDE,EAASA,SAAAF,KAdUG,EAceH,EAbjCI,EAAAA,SAASD,KAGNE,OAAOC,MAAMD,OAAOF,KAWpB,GAAGH,IAAQC,IACRG,EAAAA,SAASJ,GACZA,OAERO,EAAAC,YAAY,WAAY,4CANL,GAbG,IAACL,CAmB2C,wBAQrCM,GACxBA,EACEC,OAAOC,QAAQF,GACpBG,KAAI,EAAEC,EAAKb,KAEJ,GADSa,EAAIC,QAAQ,WAAY,OAAOC,kBACzBf,OAEtBgB,KAAK,KANY"}
package/lib/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./array/index.js"),r=require("./base64/index.js"),s=require("./click/index.js"),t=require("./color/index.js"),o=require("./console/index.js"),i=require("./crypto/index.js"),n=require("./date/index.js");require("./dom/index.js");const l=require("./env/index.js"),x=require("./error/index.js"),p=require("./identity/index.js"),u=require("./object/index.js"),c=require("./storage/index.js"),a=require("./string/index.js");require("./vue/index.js");const d=require("./dom/style.js"),j=require("./vue/expose.js"),q=require("./vue/func.js"),U=require("./vue/install.js"),E=require("./vue/props.js"),y=require("./vue/slots.js"),v=require("./vue/useRender.js"),I=require("./vue/with.js");exports.arrayUtil=e.arrayUtil,exports.base64Util=r.base64Util,exports.clickUtil=s.clickUtil,exports.colorUtil=t.colorUtil,exports.consoleDebug=o.consoleDebug,exports.consoleError=o.consoleError,exports.consoleLog=o.consoleLog,exports.consoleWarn=o.consoleWarn,exports.throwError=o.throwError,exports.cryptoUtil=i.cryptoUtil,exports.dateUtil=n.dateUtil,exports.envUtil=l.envUtil,exports.FastError=x.FastError,exports.useIdentity=p.useIdentity,exports.objectUtil=u.objectUtil,exports.CACHE_EXPIRE_SUFFIX=c.CACHE_EXPIRE_SUFFIX,exports.CACHE_PREFIX=c.CACHE_PREFIX,exports.Local=c.Local,exports.Session=c.Session,exports.useStorage=c.useStorage,exports.stringUtil=a.stringUtil,exports.addUnit=d.addUnit,exports.useExpose=j.useExpose,exports.execFunction=q.execFunction,exports.withInstall=U.withInstall,exports.withInstallDirective=U.withInstallDirective,exports.withNoopInstall=U.withNoopInstall,exports.definePropType=E.definePropType,exports.useProps=E.useProps,exports.makeSlots=y.makeSlots,exports.useRender=v.useRender,exports.withDefineType=I.withDefineType;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./array/index.js"),r=require("./base64/index.js"),t=require("./click/index.js"),s=require("./color/index.js"),o=require("./console/index.js"),i=require("./crypto/index.js"),n=require("./date/index.js");require("./dom/index.js");const l=require("./env/index.js"),x=require("./error/index.js"),p=require("./identity/index.js"),u=require("./object/index.js"),c=require("./storage/index.js"),a=require("./string/index.js");require("./vue/index.js");const d=require("./dom/style.js"),j=require("./vue/expose.js"),q=require("./vue/func.js"),U=require("./vue/install.js"),y=require("./vue/props.js"),E=require("./vue/slots.js"),g=require("./vue/useRender.js"),v=require("./vue/with.js");exports.arrayUtil=e.arrayUtil,exports.base64Util=r.base64Util,exports.clickUtil=t.clickUtil,exports.colorUtil=s.colorUtil,exports.consoleDebug=o.consoleDebug,exports.consoleError=o.consoleError,exports.consoleLog=o.consoleLog,exports.consoleWarn=o.consoleWarn,exports.throwError=o.throwError,exports.cryptoUtil=i.cryptoUtil,exports.dateUtil=n.dateUtil,exports.envUtil=l.envUtil,exports.FastError=x.FastError,exports.useIdentity=p.useIdentity,exports.objectUtil=u.objectUtil,exports.CACHE_EXPIRE_SUFFIX=c.CACHE_EXPIRE_SUFFIX,exports.CACHE_PREFIX=c.CACHE_PREFIX,exports.Local=c.Local,exports.Session=c.Session,exports.useStorage=c.useStorage,exports.stringUtil=a.stringUtil,exports.addUnit=d.addUnit,exports.styleToString=d.styleToString,exports.useExpose=j.useExpose,exports.execFunction=q.execFunction,exports.withInstall=U.withInstall,exports.withInstallDirective=U.withInstallDirective,exports.withNoopInstall=U.withNoopInstall,exports.definePropType=y.definePropType,exports.useProps=y.useProps,exports.makeSlots=E.makeSlots,exports.useRender=g.useRender,exports.withDefineType=v.withDefineType;
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fast-china/utils",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "Fast 工具库.",
5
5
  "type": "module",
6
6
  "keywords": [