New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-auto-guard

Package Overview
Dependencies
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-auto-guard - npm Package Compare versions

Comparing version 1.0.0-alpha.12 to 1.0.0-alpha.13

9

lib/index.js

@@ -406,10 +406,13 @@ "use strict";

var debug = options.debug;
var hasSpaces = (property.name || '').includes(' ') &&
["'", "\""].every(function (quote) { return !(propertyName || '').includes(quote); });
var propertyName = property.name;
var isIdentifier = propertyName[0] !== '"';
var isIdentifier = propertyName[0] !== '"' && propertyName[0] !== "'" && !hasSpaces;
var strippedName = propertyName.replace(/"/g, '');
var varName = isIdentifier
? objName + "." + propertyName
: objName + "[" + propertyName + "]";
: objName + "[\"" + strippedName + "\"]";
var propertyPath = isIdentifier
? path + "." + propertyName
: path + "[" + propertyName + "]";
: path + "[\"" + strippedName + "\"]";
var expectedType = property.type.getText();

@@ -416,0 +419,0 @@ var conditions = typeConditions(varName, property.type, addDependency, project, propertyPath, arrayDepth, true, records, options);

{
"name": "ts-auto-guard",
"version": "1.0.0-alpha.12",
"version": "1.0.0-alpha.13",
"description": "Generate type guard functions from TypeScript interfaces",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/rhys-vdw/ts-auto-guard",

@@ -201,2 +201,28 @@ import { each, pull } from 'lodash'

testProcessProject(
'generates type guards for properties with spaces in types instead of interfaces',
{
'test.ts': `
/** @see {isFoo} ts-auto-guard:type-guard */
export type Foo = {
"foo 1": number,
"bar 2": string
}`,
},
{
'test.guard.ts': `
import { Foo } from "./test";
export function isFoo(obj: any, _argumentName?: string): obj is Foo {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
typeof obj["foo 1"] === "number" &&
typeof obj["bar 2"] === "string"
)
}`,
}
)
testProcessProject(
'correctly handles default export',

@@ -203,0 +229,0 @@ {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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