Parcourir la source

Start migration to Typescript

pull/674/head
Guillaume Vincent il y a 3 ans
Parent
révision
81e98b18c2
7 fichiers modifiés avec 425 ajouts et 373 suppressions
  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 Voir le fichier

@@ -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 Voir le fichier

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

packages/lesspass-crypto/index.js → packages/lesspass-crypto/index.ts Voir le fichier

@@ -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 Voir le fichier

@@ -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 Voir le fichier

@@ -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 Voir le fichier

@@ -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
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


Chargement…
Annuler
Enregistrer