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

harpake

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

harpake - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

types/interfaces.d.ts

29

dist/index.js

@@ -15,9 +15,13 @@ 'use strict';

}
const file = path.join(root, rootName + ".json");
let samples = [];
if (fs.existsSync(file)) {
samples = JSON.parse(fs.readFileSync(file).toString());
const samplesFile = path.join(root, "samples.json");
let samples = {};
if (fs.existsSync(samplesFile)) {
samples = JSON.parse(fs.readFileSync(samplesFile).toString());
}
const interfaces = JsonToTS([...samples, input], { rootName });
fs.writeFileSync(file, JSON.stringify([...samples, input], null, 2));
const nameSamples = samples[rootName] || [];
const interfaces = JsonToTS([...nameSamples, input], { rootName });
const newSamples = { ...samples, [rootName]: [...nameSamples, input] };
fs.writeFileSync(samplesFile, JSON.stringify(newSamples,
// TODO remove these
null, 2));
const typefile = path.join(path.dirname(_getCallerFile()), rootName + ".ts");

@@ -27,2 +31,15 @@ fs.writeFileSync(typefile, interfaces

.replace("interface " + rootName, "export interface " + rootName));
const typeFile = Object.entries(newSamples).reduce((typeFile, [rName, samples]) => {
const interfaces = JsonToTS([...nameSamples, input], { rootName });
return typeFile + interfaces.join("\n\n");
}, "");
const foo = `
export declare type All = {
${Object.keys(newSamples)
.map((k) => `${k}: ${k};`)
.join("\n")}
};
`;
fs.writeFileSync(path.join(__dirname, "../types/", "interfaces.d.ts"), typeFile + foo);
}

@@ -29,0 +46,0 @@ catch (error) {

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("json-to-ts"),require("fs"),require("path")):"function"==typeof define&&define.amd?define(["json-to-ts","fs","path"],t):(e=e||self).harpake=t(e.JsonToTS,e.fs,e.path)}(this,(function(e,t,r){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;const n=(r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r).join(process.cwd(),".harpake");return function(o,c){try{t.existsSync(n)||t.mkdirSync(n);const a=r.join(n,o+".json");let i=[];t.existsSync(a)&&(i=JSON.parse(t.readFileSync(a).toString()));const s=e([...i,c],{rootName:o});t.writeFileSync(a,JSON.stringify([...i,c],null,2));const f=r.join(r.dirname(function(){try{var e,t,r=new Error;for(Error.prepareStackTrace=function(e,t){return t},t=r.stack.shift().getFileName();r.stack.length;)if(e=r.stack.shift().getFileName(),t!==e)return e}catch(r){}return}()),o+".ts");t.writeFileSync(f,s.join("\n\n").replace("interface "+o,"export interface "+o))}catch(e){console.error(e)}return c}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("json-to-ts"),require("fs"),require("path")):"function"==typeof define&&define.amd?define(["json-to-ts","fs","path"],t):(e=e||self).harpake=t(e.JsonToTS,e.fs,e.path)}(this,(function(e,t,n){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;const r=(n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n).join(process.cwd(),".harpake");return function(o,c){try{t.existsSync(r)||t.mkdirSync(r);const i=n.join(r,"samples.json");let s={};t.existsSync(i)&&(s=JSON.parse(t.readFileSync(i).toString()));const a=s[o]||[],f=e([...a,c],{rootName:o}),l={...s,[o]:[...a,c]};t.writeFileSync(i,JSON.stringify(l,null,2));const p=n.join(n.dirname(function(){try{var e,t,n=new Error;for(Error.prepareStackTrace=function(e,t){return t},t=n.stack.shift().getFileName();n.stack.length;)if(e=n.stack.shift().getFileName(),t!==e)return e}catch(n){}return}()),o+".ts");t.writeFileSync(p,f.join("\n\n").replace("interface "+o,"export interface "+o));const u=Object.entries(l).reduce((t,[n,r])=>t+e([...a,c],{rootName:o}).join("\n\n"),""),d=`\n\n\t\t\texport declare type All = {\n\t\t\t\t${Object.keys(l).map(e=>`${e}: ${e};`).join("\n")}\n\t\t\t};\n\t\t`;t.writeFileSync(n.join(__dirname,"../types/","interfaces.d.ts"),u+d)}catch(e){console.error(e)}return c}}));
{
"version": "0.0.1",
"version": "0.0.2",
"name": "harpake",

@@ -4,0 +4,0 @@ "repository": "rikukissa/harpake",

@@ -1,1 +0,2 @@

export default function harpake<T = any>(rootName: string, input: T): T;
import { All } from "./interfaces";
export default function harpake<ID extends string, T = any>(rootName: ID, input: T): All extends Record<ID, any> ? All[ID] : T;

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