Using SJCL library in Angular2

房东的猫 提交于 2019-12-23 04:58:12

问题


In my app i would like to use "Stanford Javascript Crypto Library" which has a typing and i also see https://github.com/Evgenus/sjcl-typescript-definitions.

I dont understand how i can use it in my project. How can i use the command sjcl.encrypt("password", "data") in my project.

i am using angular 4, angular-cli beta 2

i have run npm install --save-dev @types/sjcl

tsconfig.app.json

{
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "types": [ "sjcl" ]
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ],
  "extends": "../tsconfig.json"
}

回答1:


You need to install sjcl package: npm install --save sjcl
With types (not necessary): npm install --save sjcl @types/sjcl

Then add import in your code where you want to use sjcl:

import * as sjcl from 'sjcl';

You don't need to add sjcl into tsconfig.app.json file.


Important! Also if you look into type definitions you will see they were written for sjcl v1.0.1, last version of sjcl is 1.0.6 so you might get type errors for some functions.



来源:https://stackoverflow.com/questions/43029690/using-sjcl-library-in-angular2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!