EBIA

Tag: JSON

Using Shell Commands in JS-Projects or in Scripts in package.json

1. ShellJS

ShellJS is a portable (Windows/Linux/OS X) implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate your shell script’s dependency on Unix while still keeping its familiar and powerful commands. You can also install it globally so you can run it from outside Node projects – say goodbye to those gnarly Bash scripts!

$ npm install [-g] shelljs

2. Shx

shx is a wrapper around ShellJS Unix commands, providing an easy solution for simple Unix-like, cross-platform commands in npm package scripts.

$ npm install shx --save-dev

Difference Between ShellJS and shx

  • ShellJS: Good for writing long scripts, all in JS, running via NodeJS (e.g. node myScript.js).
  • shx: Good for writing one-off commands in npm package scripts (e.g. "clean": "shx rm -rf out/").

 

Angular CLI with SSL

in package.json

"scripts": {
    ..
    "https": "ng serve --ssl true --ssl-key \"certs/localhost.key\" --ssl-cert \"certs/localhost.crt\"",
    ..
}

Rendering Data from Observables

Elvis Operator within Template

{{ (__responseData | async)?.calculation | json }}

Or with ngFor

@Component({
  selector: 'my-app',
  providers: [HTTP_PROVIDERS],
  template: `
    <div *ngFor="let calculation of calculations | async">
      Gross: {{ calculation.gross }}<br>
      Net: {{ calculation.net }}
    </div>
  `,
  directives: [NgFor]
})
export class App {
  calculations: Observable<{gross:number; net:number}[]>;

  constructor(private _http: Http) {
    this.calculations = this._http.get("./data.json")
                            .map(res => res.json().calculation)
  }
}

>> See plunker here

JSON Related

Extend JSON Arrays with lodash

lodash.each($scope.myDataFromREST, function(item) {
    lodash.extend(item, {
        "edit": false,
        "some": {
            "foo": "bar"
        }
    });
});

Copyright © 2020 EBIA

Theme by Anders NorenUp ↑