Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remix-typedjson

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remix-typedjson - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

4

CHANGELOG.md
# CHANGELOG
## 🚀 v0.3.1
- 🐛 Add support for dotted properties in serialized object [#22](https://github.com/kiliman/remix-typedjson/issues/22)
## 🚀 v0.3.0

@@ -4,0 +8,0 @@

3

dist/esm/typedjson.d.ts

@@ -12,2 +12,3 @@ type NonJsonTypes = 'date' | 'set' | 'map' | 'regexp' | 'bigint' | 'undefined' | 'infinity' | '-infinity' | 'nan' | 'error' | string;

declare function deserialize<T>({ json, meta }: TypedJsonResult): T | null;
export declare const splitKey: (key: string) => string[];
declare function applyMeta<T>(data: T, meta: MetaType): T;

@@ -28,4 +29,4 @@ type TypedJsonResult = {

};
export { serialize, deserialize, stringify, parse, applyMeta };
export { applyMeta, deserialize, parse, serialize, stringify };
export type { MetaType, TypedJsonResult };
export default typedjson;

@@ -32,2 +32,6 @@ let customTypeMap = new Map();

}
// handle dotted keys
if (key.includes('.')) {
key = `[${key}]`;
}
let metaKey = `${keys[keys.length - 1]}${key}`;

@@ -135,6 +139,31 @@ const valueType = typeof value;

}
export const splitKey = (key) => {
// key is a dotted path
// may contain escaped dots which are keys wrapped in []
// example [b.c].d => ['b.c', 'd']
const keys = [];
const parts = key.split('.');
for (let i = 0; i < parts.length; i++) {
if (parts[i].startsWith('[')) {
let k = parts[i].substring(1);
let j = i + 1;
while (!parts[j].endsWith(']')) {
k += `.${parts[j]}`;
j++;
}
k += `.${parts[j].slice(0, -1)}`;
keys.push(k);
i = j;
}
else {
keys.push(parts[i]);
}
}
return keys;
};
function applyMeta(data, meta) {
const customTypeMapValues = Array.from(customTypeMap.values());
for (const key of Object.keys(meta)) {
applyConversion(data, key.split('.'), meta[key]);
const keys = splitKey(key);
applyConversion(data, keys, meta[key]);
}

@@ -220,3 +249,3 @@ return data;

};
export { serialize, deserialize, stringify, parse, applyMeta };
export { applyMeta, deserialize, parse, serialize, stringify };
export default typedjson;

@@ -12,2 +12,3 @@ type NonJsonTypes = 'date' | 'set' | 'map' | 'regexp' | 'bigint' | 'undefined' | 'infinity' | '-infinity' | 'nan' | 'error' | string;

declare function deserialize<T>({ json, meta }: TypedJsonResult): T | null;
export declare const splitKey: (key: string) => string[];
declare function applyMeta<T>(data: T, meta: MetaType): T;

@@ -28,4 +29,4 @@ type TypedJsonResult = {

};
export { serialize, deserialize, stringify, parse, applyMeta };
export { applyMeta, deserialize, parse, serialize, stringify };
export type { MetaType, TypedJsonResult };
export default typedjson;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyMeta = exports.parse = exports.stringify = exports.deserialize = exports.serialize = exports.registerCustomType = void 0;
exports.stringify = exports.serialize = exports.parse = exports.deserialize = exports.applyMeta = exports.splitKey = exports.registerCustomType = void 0;
let customTypeMap = new Map();

@@ -36,2 +36,6 @@ function registerCustomType(entry) {

}
// handle dotted keys
if (key.includes('.')) {
key = `[${key}]`;
}
let metaKey = `${keys[keys.length - 1]}${key}`;

@@ -141,6 +145,32 @@ const valueType = typeof value;

exports.deserialize = deserialize;
const splitKey = (key) => {
// key is a dotted path
// may contain escaped dots which are keys wrapped in []
// example [b.c].d => ['b.c', 'd']
const keys = [];
const parts = key.split('.');
for (let i = 0; i < parts.length; i++) {
if (parts[i].startsWith('[')) {
let k = parts[i].substring(1);
let j = i + 1;
while (!parts[j].endsWith(']')) {
k += `.${parts[j]}`;
j++;
}
k += `.${parts[j].slice(0, -1)}`;
keys.push(k);
i = j;
}
else {
keys.push(parts[i]);
}
}
return keys;
};
exports.splitKey = splitKey;
function applyMeta(data, meta) {
const customTypeMapValues = Array.from(customTypeMap.values());
for (const key of Object.keys(meta)) {
applyConversion(data, key.split('.'), meta[key]);
const keys = (0, exports.splitKey)(key);
applyConversion(data, keys, meta[key]);
}

@@ -147,0 +177,0 @@ return data;

{
"name": "remix-typedjson",
"version": "0.3.0",
"version": "0.3.1",
"description": "This package is a replacement for superjson to use in your Remix app. It handles a subset of types that `superjson` supports, but is faster and smaller.",

@@ -5,0 +5,0 @@ "browser": "/dist/esm/index.js",

@@ -54,3 +54,3 @@ # remix-typedjson

❌ export const loader: LoaderFunction = async ({request}) => {}
❌ export const action: LoaderFunction = async ({request}) => {}
❌ export const action: ActionFunction = async ({request}) => {}

@@ -96,3 +96,3 @@ ✅ export const loader = async ({request}: DataFunctionArgs) => {}

## typeddefer
## `typeddefer`

@@ -114,5 +114,9 @@ ✨ New in v0.3.0

## `<TypedAwait>`
In your route component, use the new `<TypedAwait>` component instead of the
Remix `<Await>` component
### Usage
```js

@@ -119,0 +123,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc