javascript object2object mapper - javascript

I'm searching for a javascript mapping library I can easily integrate in my angularjs project.
I use some json objects in my javascript code that are slightly different from the json structure given by my back-end.
I have found this interesting library (https://github.com/wankdanker/node-object-mapper) that lets you specify a mapping through another object, but unfortunately it seems to work only in a nodejs environment and not in the browser.
Does anyone know a similar library working in a browser too?

Last year, I have created a port of the C# AutoMapper implementation to TypeScript / JavaScript exactly for this scenario. I have put the code at GitHub (https://b.ldmn.nl/AutoMapperTS). You can also use the library directly using the automapper-ts NPM or Bower package.
The library is almost fully documented. Furthermore, quite a lot of Jasmine unit tests are already available (code coverage is about 95%). They should provide you with some explanation of what you need.
I hope this library suits your needs. Should you have any questions and/or remarks, please don't hesitate contacting me!

Related

Is it possible to run Cucumber.js programmatically?

I'm constructing a e2e-testing framework which utilizes cucumber. The framework is meant to be used by our customers who build web-applications with our tooling.
I'd like to ensure that the framework is functioning correctly by testing it. Unfortunately it seems that the Cucumber.js API has no means to run the program without using a CLI.
I'd much prefer to avoid running tests based on the outcome of a CLI.
So, my question, is it possible to run cucumber.js programmatically?
I can't find any documentation on this. Thanks in advance for any answers.
There seems to be some functionality to do this. It's undocumented however. There is an issue [ https://github.com/cucumber/cucumber-js/issues/1004 ] with a request to update the API Usage documentation. However, the issue dates back to 2018 and hasn't received a whole lot of attention since.
use the child_process module to spawn cucumber.

Flutter and Openlayers - including js libraries in flutter

Coming from the js/cordova based cross-platform universe, I am digging into flutter lately. So I wonder about the options to make use of the various js libraries in flutter directly. More concrete I am interested in using the openlayers library in flutter to create a versatile map view with various functions for drawing and editing. So I wonder what options are there to include it.
So far I see two major ways:
Using a webview:
Even though there is no native webview widget yet in flutter there is a plugin for this (https://github.com/dart-flitter/flutter_webview_plugin). The main advantage I see here is to use the openlayers library "as it is", however the plugin is in kinda early state and I could not see a way to establish communication between flutter and js functions in the webview yet. Futhermore (this is just my assumption) using the webview is probably slower than creating a proper widget with dart code.
Creating a custom widget:
I have seen there are ways to convert js code direcly to dart, using package js (https://pub.dartlang.org/packages/js) and for typings js_facade_gen (https://github.com/dart-lang/js_facade_gen) like it is done with the chartjs library (https://github.com/google/chartjs.dart/). So similar to this it should be possible to automatically convert the openlayers lib to dart. The main issue however is to integrate this into flutter, since openlayers is using a html5 canvas if I'm correct. Also the chartjs.dart package does not giva any hints how to include it in a flutter app. I've also seen there is a leaflet plugin (https://github.com/apptreesoftware/flutter_map) which is creating their own widget, however they seem to rewrite the code by hand (?), which is for openlyers with 20.000 lines of code not really an option atm.
I'm aware that this is not the best question format for this site, nonetheless I hope someone has some advice or hints on where to start or how to implement this, especially for the 2nd option - the first one is more straight forward. Or if you can think of a third option, go ahead please, I'm grateful for any clues.
The only way to make use of JS in Flutter is using WebView.
Dart compiles to JS only for browser applications, for Flutter it compiles to native machine code.
convert js code direcly to dart, using package js
package JS doesn't convert JS, it just creates proxies for JS functions to be able to call them from Dart, but that is also only supported in Dart web applications.

Angular2 application half in Typescript and Javascript

I currently have a large JavaScript application with a lot of code written in vanilla Javascript for a specific platform for where I work.
I need to transform this into a web application I can open in the browser. This should be able to be done relatively easy by swapping out the components from my current application to the components of another web technology.
However since Angular2 is written in TypeScript, if I was to choose it as the framework I use, should I really also be rewriting the rest of my non-component JavaScript to TypeScript to or will I not need to do this.
Would it be a bad idea to have an application which was half TypeScript and half JavaScript like this?
It's not a bad idea to mix TypeScript and JavaScript. I do it every day. But you have to now that it may be very painful in some cases. So I can only advice to enforce migration to TypeScript as fast as possible.
I would suggest you to read this introduction to migration from JavaScript to TypeScript: https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html
This might also be a valuable source: https://basarat.gitbooks.io/typescript/content/docs/types/migrating.html but I have the impression that the author has a very narrow opinion on how to work with typescript so just don't take everything there as it is, but just as a suggestion.
There are also a lot of other resources about migrating from JavaScript to TypeScript.
For the last month of migration to TypeScript I can say, that in many cases you can simply change your JavaScript to a TypeScript file and add exports. Than you need to add the needed imports in the other places and everything works just like before.
If you can make sure, that you only use old JavaScript in your TypeScript and not the other way round you can split your project into to packages. Load the JavaScript into global as done before and than create Typings for the parts of your JavaScript you use in TypeScript.

Create Swagger-docs for API written in Express 4.x

I have a server written with Node and Express 4. I also have a customer which wants this to be documented with Swagger. How can this be done?
I've looked into the following tools:
swagger-node-express: Lets you do exactly what I want, except it does not support Express 4.x
Swagger 2.0 - Node-Express-4.x: Same as above but with a different approach. Could be used, except I don't find much documentation on setting it up (and I'm too slow to get it without docs)
Tools like swaggerize-express and Swaggers own tool for Node would work if I started from scratch, but I just want a way to easiliy add docs to my project so that Swagger can read it.
It wouldn't work in the long run to write a doc-file that Swagger can read because then I'd have to update it. I want to document everything in the code and not a Swagger- or readme-file, and let the documentation be available through a Swagger-UI automatically.
I may have overlooked something here, but I can't seem to find anything to help me.All suggestions are welcome. Thanks in advance.
I highly recommend looking into Loopback framework. It's framework for creating REST APIs on stereoids. It is using Express under the hood and is created by company StrongLoop, which also maintains Express project itself now.
It supports Swagger out of the box.

Spoofing an API with SinonJS?

When developing an API (in my case an API that wraps around a websockets service), is there a good way of giving it's skeletal implementation to another developer so that he can work independent of me? If my API is still in the design phase for example, I'm thinking that I could give an outline of the methods that will be available and all the possible return types.
I realise that I could just give him a dummy object with all the methods inside but it would be great if that dummy object could be tied in with his unit tests and so on.
I've been looking at [SinonJs][1]: http://sinonjs.org/ and in particular at the Stub functionality it provides. However I am not sure if what I've outlined here is an appropriate use of stubs.
Any advice appreciated!
EDIT:
I guess this question should of been:
'How to write unit tests using Jasmine, Sinon and a mock API'
It was a bit of a silly question because it turns out that Sinon actually has it's own 'fake server' which is very easy to use. In ignorance of this my first idea was to mock or spy on XHR stuff.
The code I ended up with is here: https://gist.github.com/james-gardner/11405316
See 'DummyViewSpec.js' for examples of the fake server stuff. Edits welcome!
If you are asking about an easy way to have a web app (or other REST) API up and running - http://flatironjs.org/ might be a good option for you. It's full JS stack both on the server (node.js) and client. However, you can do an API mockups with any other routing library (search npm - there are A LOT of them).
I hope it helps.
There is a tool to mockup the whole APIs using schema and random data with types
https://github.com/homerquan/kakuen
I created and used it to inject dependance of api

Categories

Resources