@zero-library/common 2.1.7 → 2.1.9

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.cjs.js CHANGED
@@ -741,6 +741,23 @@ var getWebSocketUrl = (path, customHost) => {
741
741
  const host = customHost || window.location.host;
742
742
  return `${protocol}//${host}${path}`;
743
743
  };
744
+ function transform(source, fieldMap) {
745
+ const result = {};
746
+ for (const [targetKey, mapping] of Object.entries(fieldMap)) {
747
+ const key = targetKey;
748
+ if (typeof mapping === "function") {
749
+ result[key] = mapping(source);
750
+ } else if (typeof mapping === "string" && source && mapping in source) {
751
+ result[key] = source[mapping];
752
+ } else {
753
+ result[key] = mapping;
754
+ }
755
+ }
756
+ return result;
757
+ }
758
+ function transforms(sources, fieldMap) {
759
+ return sources?.map((source) => transform(source, fieldMap)) || [];
760
+ }
744
761
 
745
762
  // src/hooks/useDeepEffect.ts
746
763
  function useDeepEffect(effect, deps) {
@@ -5354,6 +5371,8 @@ exports.textAreaView = textAreaView;
5354
5371
  exports.themeConfig = themeConfig;
5355
5372
  exports.times = times;
5356
5373
  exports.toFixed = toFixed;
5374
+ exports.transform = transform;
5375
+ exports.transforms = transforms;
5357
5376
  exports.useCreateValtioContext = useCreateValtioContext;
5358
5377
  exports.useDebounce = useDebounce;
5359
5378
  exports.useDeepEffect = useDeepEffect;