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

@krlwlfrt/tsg

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@krlwlfrt/tsg - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

14

CHANGELOG.md

@@ -0,1 +1,15 @@

# [0.4.0](https://gitlab.com/krlwlfrt/tsg/compare/v0.3.1...v0.4.0) (2020-03-04)
### Bug Fixes
* remove extraneous file ([eff6da6](https://gitlab.com/krlwlfrt/tsg/commit/eff6da69a37fed83bda0419c82c1d49067df31c4))
### Features
* add union type ([cfc4c55](https://gitlab.com/krlwlfrt/tsg/commit/cfc4c55395d40fe6a4a8cfff5ec41f659d9fb001))
## [0.3.1](https://gitlab.com/krlwlfrt/tsg/compare/v0.3.0...v0.3.1) (2020-02-18)

@@ -2,0 +16,0 @@

25

lib/index.d.ts

@@ -18,3 +18,3 @@ /**

/**
* Optional value for attributes
* Default value
*/

@@ -26,3 +26,3 @@ value?: unknown;

*/
export declare type Type = Entity | Property;
export declare type Type = Entity | Property | Union;
/**

@@ -33,7 +33,7 @@ * An entity

/**
* Parent interface of the interface
* Parent entity
*/
parent?: ThingWithNameAndNamespace;
/**
* List of properties of the interface
* List of properties
*/

@@ -68,3 +68,3 @@ properties: Property[];

/**
* Value of the property
* Value of the attribute
*/

@@ -74,2 +74,11 @@ value: boolean | number | string;

/**
* A union of types
*/
export interface Union extends ThingWithNameAndNamespace {
/**
* List of united types
*/
unitedTypes: (Type | string | number | boolean)[];
}
/**
* Check if a Type is an Entity

@@ -81,2 +90,8 @@ *

/**
* Check if a Type is a Union
*
* @param type Type to check
*/
export declare function isUnion(type: Type): type is Union;
/**
* Check if a ThingWithNameAndNamespace is an Attribute

@@ -83,0 +98,0 @@ *

30

lib/index.js

@@ -30,2 +30,14 @@ "use strict";

/**
* Check if a Type is a Union
*
* @param type Type to check
*/
function isUnion(type) {
if (!('unitedTypes' in type)) {
return false;
}
return Array.isArray(type.unitedTypes);
}
exports.isUnion = isUnion;
/**
* Check if a ThingWithNameAndNamespace is an Attribute

@@ -91,3 +103,4 @@ *

let output = `/* tslint:disable */\n`;
for (const type of types) {
while (types.length > 0) {
const type = types.shift();
output += '\n';

@@ -140,2 +153,15 @@ if (typeof type.description === 'string') {

}
else if (isUnion(type)) {
output += `export type ${nameGenerator(type)} = ${type.unitedTypes.map((unitedType) => {
if (typeof unitedType === 'string') {
return `'${unitedType}'`;
}
if (typeof unitedType === 'number' || typeof unitedType === 'boolean') {
return unitedType;
}
return nameGenerator(unitedType);
})
.join(' | ')};
`;
}
else {

@@ -149,2 +175,2 @@ output += `export type ${nameGenerator(type)} = ${propertyTypeGenerator(type)};

exports.generateTypeScript = generateTypeScript;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7Ozs7Ozs7O0dBYUc7O0FBaUZIOzs7O0dBSUc7QUFDSCxTQUFnQixRQUFRLENBQUMsSUFBVTtJQUNqQyxJQUFJLENBQUMsQ0FBQyxZQUFZLElBQUksSUFBSSxDQUFDLEVBQUU7UUFDM0IsT0FBTyxLQUFLLENBQUM7S0FDZDtJQUVELE9BQU8sS0FBSyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUM7QUFDeEMsQ0FBQztBQU5ELDRCQU1DO0FBRUQ7Ozs7R0FJRztBQUNILFNBQWdCLFdBQVcsQ0FBQyxLQUFnQztJQUMxRCxJQUFJLENBQUMsQ0FBQyxPQUFPLElBQUksS0FBSyxDQUFDLEVBQUU7UUFDdkIsT0FBTyxLQUFLLENBQUM7S0FDZDtJQUVELE9BQU8sT0FBTyxLQUFLLENBQUM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pQkFDMUI7Z0JBRUQsSUFBSSxPQUFPLFVBQVUsS0FBSyxRQUFRLElBQUksT0FBTyxVQUFVLEtBQUssU0FBUyxFQUFFO29CQUNyRSxPQUFPLFVBQVUsQ0FBQztpQkFDbkI7Z0JBRUQsT0FBTyxhQUFhLENBQUMsVUFBVSxDQUFDLENBQUM7WUFDbkMsQ0FBQyxDQUFDO2lCQUNDLElBQUksQ0FBQyxLQUFLLENBQUM7Q0FDbkIsQ0FBQztTQUNHO2FBQU07WUFDTCxNQUFNLElBQUksZUFBZSxhQUFhLENBQUMsSUFBSSxDQUFDLE1BQU0scUJBQXFCLENBQUMsSUFBSSxDQUFDO0NBQ2xGLENBQUM7U0FDRztLQUNGO0lBRUQsT0FBTyxNQUFNLENBQUM7QUFDaEIsQ0FBQztBQTlGRCxnREE4RkMifQ==
{
"name": "@krlwlfrt/tsg",
"version": "0.3.1",
"version": "0.4.0",
"description": "TypeScript generator",

@@ -5,0 +5,0 @@ "repository": {

@@ -24,2 +24,3 @@ /*

description?: string;
/**

@@ -36,3 +37,3 @@ * Name of the thing

/**
* Optional value for attributes
* Default value
*/

@@ -45,3 +46,3 @@ value?: unknown;

*/
export type Type = Entity | Property;
export type Type = Entity | Property | Union;

@@ -53,3 +54,3 @@ /**

/**
* Parent interface of the interface
* Parent entity
*/

@@ -59,3 +60,3 @@ parent?: ThingWithNameAndNamespace;

/**
* List of properties of the interface
* List of properties
*/

@@ -95,3 +96,3 @@ properties: Property[];

/**
* Value of the property
* Value of the attribute
*/

@@ -102,2 +103,12 @@ value: boolean | number | string;

/**
* A union of types
*/
export interface Union extends ThingWithNameAndNamespace {
/**
* List of united types
*/
unitedTypes: (Type | string | number | boolean)[];
}
/**
* Check if a Type is an Entity

@@ -116,2 +127,15 @@ *

/**
* Check if a Type is a Union
*
* @param type Type to check
*/
export function isUnion(type: Type): type is Union {
if (!('unitedTypes' in type)) {
return false;
}
return Array.isArray(type.unitedTypes);
}
/**
* Check if a ThingWithNameAndNamespace is an Attribute

@@ -188,3 +212,5 @@ *

for (const type of types) {
while (types.length > 0) {
const type = types.shift() as Type;
output += '\n';

@@ -249,2 +275,16 @@

output += `}\n`;
} else if (isUnion(type)) {
output += `export type ${nameGenerator(type)} = ${type.unitedTypes.map((unitedType) => {
if (typeof unitedType === 'string') {
return `'${unitedType}'`;
}
if (typeof unitedType === 'number' || typeof unitedType === 'boolean') {
return unitedType;
}
return nameGenerator(unitedType);
})
.join(' | ')};
`;
} else {

@@ -251,0 +291,0 @@ output += `export type ${nameGenerator(type)} = ${propertyTypeGenerator(type)};

Sorry, the diff of this file is too big to display

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