Преглед на файлове

Start migration to Typescript

pull/674/head
Guillaume Vincent преди 3 години
родител
ревизия
81e98b18c2
променени са 7 файла, в които са добавени 425 реда и са изтрити 373 реда
  1. +5
    -2
      package.json
  2. +2
    -0
      packages/lesspass-crypto/.gitignore
  3. +11
    -13
      packages/lesspass-crypto/index.ts
  4. +15
    -3
      packages/lesspass-crypto/package.json
  5. +1
    -5
      packages/lesspass-crypto/test.ts
  6. +16
    -0
      packages/lesspass-crypto/tsconfig.json
  7. +375
    -350
      yarn.lock

+ 5
- 2
package.json Целия файл

@@ -9,12 +9,15 @@
"packages/*"
],
"devDependencies": {
"@types/jest": "^27.0.3",
"browserify": "^17.0.0",
"jest": "^27.2.4",
"jest": "^27.3.1",
"karma": "^6.3.4",
"karma-browserify": "^8.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^2.0.1",
"mocha": "^9.1.2"
"mocha": "^9.1.2",
"ts-jest": "^27.0.7",
"typescript": "^4.5.2"
}
}

+ 2
- 0
packages/lesspass-crypto/.gitignore Целия файл

@@ -0,0 +1,2 @@
node_modules
dist

packages/lesspass-crypto/index.js → packages/lesspass-crypto/index.ts Целия файл

@@ -1,5 +1,5 @@
function stringToArrayBuffer(string) {
const base64String = unescape(encodeURIComponent(string));
export function stringToArrayBuffer(s: string) {
const base64String = unescape(encodeURIComponent(s));
const charList = base64String.split("");
const arrayBuffer = [];
for (let i = 0; i < charList.length; i += 1) {
@@ -8,7 +8,7 @@ function stringToArrayBuffer(string) {
return new Uint8Array(arrayBuffer);
}

function arrayBufferToHex(arrayBuffer) {
export function arrayBufferToHex(arrayBuffer: Iterable<number>) {
const byteArray = new Uint8Array(arrayBuffer);
let str = "";
for (let i = 0; i < byteArray.byteLength; i += 1) {
@@ -17,20 +17,18 @@ function arrayBufferToHex(arrayBuffer) {
return str;
}

function getAlgorithm(algorithm) {
const algorithms = {
export function getAlgorithm(algorithm: string) {
const algorithms: { [k: string]: string } = {
sha1: "SHA-1",
"sha-1": "SHA-1",
sha256: "SHA-256",
"sha-256": "SHA-256",
sha512: "SHA-512",
"sha-512": "SHA-512",
"sha-512": "SHA-512"
};
return algorithms[algorithm.toLowerCase()];
const lowercaseAlgorithm = algorithm.toLowerCase();
if (lowercaseAlgorithm in algorithms) {
return algorithms[lowercaseAlgorithm];
}
return "SHA-256";
}

module.exports = {
stringToArrayBuffer,
arrayBufferToHex,
getAlgorithm,
};

+ 15
- 3
packages/lesspass-crypto/package.json Целия файл

@@ -5,10 +5,22 @@
"license": "GPL-3.0",
"author": "Guillaume Vincent <guillaume@oslab.fr>",
"files": [
"index.js"
"dist"
],
"main": "index.js",
"type": "module",
"exports": "./dist/index.js",
"types": "dist",
"scripts": {
"test": "jest"
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"build": "rm -rf dist && tsc",
"prepare": "npm run build"
},
"jest": {
"preset": "ts-jest/presets/default-esm",
"globals": {
"ts-jest": {
"useESM": true
}
}
}
}

packages/lesspass-crypto/test.js → packages/lesspass-crypto/test.ts Целия файл

@@ -1,8 +1,4 @@
const {
stringToArrayBuffer,
arrayBufferToHex,
getAlgorithm,
} = require("./index");
import { stringToArrayBuffer, arrayBufferToHex, getAlgorithm } from ".";

test("stringToArrayBuffer", () => {
expect(stringToArrayBuffer("ȧ")[0]).toBe(200);

+ 16
- 0
packages/lesspass-crypto/tsconfig.json Целия файл

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "ES2019",
"module": "ES2020",
"moduleResolution": "node",
"declaration": true,
"outDir": "dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"skipLibCheck": true
},
"include": ["index.ts"]
}

+ 375
- 350
yarn.lock
Файловите разлики са ограничени, защото са твърде много
Целия файл


Зареждане…
Отказ
Запис