Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
typedconverter
Advanced tools
Convert object into classes match with TypeScript type annotation
Convert object into classes match with TypeScript type annotation
import createConverter from "typedconverter";
const convert = createConverter()
const numb = convert("12345", Number) //return number 12345
const numb = convert("YES", Boolean) //return true
const numb = convert("2019-1-1", Date) //return date 1/1/2019
Expected type can be specified in the configuration, than you can omit expected type on the second parameter of the convert
function. Useful when you want to covert several times without specifying expected type.
import createConverter from "typedconverter";
const convert = createConverter({type: Number})
const numb = convert("12345")
const numb1 = convert("-12345")
const numb2 = convert("12345.123")
TypedConvert uses tinspector to get type metadata, so it aware about TypeScript type annotation.
import createConverter from "typedconverter";
import reflect from "tinspector"
const convert = createConverter()
reflect.parameterProperties()
class AnimalClass {
constructor(
public id: number,
public name: string,
public deceased: boolean,
public birthday: Date
) { }
}
//return instance of AnimalClass with appropriate properties type
const data = convert({
id: "200",
name: "Mimi",
deceased: "ON",
birthday: "2018-1-1" },
AnimalClass)
Convert into array by providing array of type in the expected type.
import createConverter from "typedconverter";
const convert = createConverter()
const numb = convert(["1", "2", "-3"], [Number])
Provided custom converter on the configuration
import createConverter from "typedconverter";
const convert = createConverter({
type: Boolean,
converters: [{ key: Boolean, converter: x => "Custom Boolean" }]
})
const numb = convert("True") //result: "Custom Boolean"
FAQs
Convert object into classes match with TypeScript type annotation
The npm package typedconverter receives a total of 17 weekly downloads. As such, typedconverter popularity was classified as not popular.
We found that typedconverter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.