Skip to content

Commit

Permalink
chore: refactor util from js to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jithyaniag authored and SoonIter committed Jul 21, 2024
1 parent 6180152 commit e1440e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
4 changes: 0 additions & 4 deletions packages/rspack/src/util/cleverMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,11 @@ const parseObject = (obj: Obj): ParsedObject => {
const entry = getInfo(key);
if (entry.byProperty === undefined) {
entry.byProperty = byProperty;
entry.byValues = new Map();
} else if (entry.byProperty !== byProperty) {
throw new Error(
`${byProperty} and ${entry.byProperty} for a single property is not supported`
);
}
if (entry.byValues == undefined) {
throw new Error(`unexpected "undefined" for byValue`);
}
entry.byValues.set(byValue, obj[key]);
if (byValue === "default") {
for (const otherByValue of Object.keys(byObj)) {
Expand Down
30 changes: 15 additions & 15 deletions packages/rspack/src/util/createHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class BulkUpdateDecorator extends Hash {
buffer: string;

/**
* @param {Hash | function(): Hash} hashOrFactory function to create a hash
* @param {string=} hashKey key for caching
* @param hashOrFactory function to create a hash
* @param hashKey key for caching
*/
constructor(hashOrFactory: Hash | (() => Hash), hashKey?: string) {
super();
Expand All @@ -45,9 +45,9 @@ class BulkUpdateDecorator extends Hash {

/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @param {string|Buffer} data data
* @param {string=} inputEncoding data encoding
* @returns {this} updated hash
* @param data data
* @param inputEncoding data encoding
* @returns updated hash
*/
update(data: string | Buffer, inputEncoding?: string): this {
if (
Expand All @@ -74,8 +74,8 @@ class BulkUpdateDecorator extends Hash {

/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @param {string=} encoding encoding of the return value
* @returns {string|Buffer} digest
* @param encoding encoding of the return value
* @returns digest
*/
digest(encoding?: string): string | Buffer {
let digestCache: Map<string, string> | undefined;
Expand Down Expand Up @@ -115,11 +115,11 @@ class DebugHash extends Hash {

/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @param {string|Buffer} data data
* @param {string=} inputEncoding data encoding
* @returns {this} updated hash
* @param data data
* @param _inputEncoding data encoding
* @returns updated hash
*/
update(data: string | Buffer, inputEncoding?: string) {
update(data: string | Buffer, _inputEncoding?: string): this {
if (typeof data !== "string") data = data.toString("utf-8");
if (data.startsWith("debug-digest-")) {
data = Buffer.from(data.slice("debug-digest-".length), "hex").toString();
Expand All @@ -130,8 +130,8 @@ class DebugHash extends Hash {

/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @param {string=} encoding encoding of the return value
* @returns {string|Buffer} digest
* @param encoding encoding of the return value
* @returns digest
*/
digest(encoding?: BufferEncoding) {
return (
Expand All @@ -142,8 +142,8 @@ class DebugHash extends Hash {

/**
* Creates a hash by name or function
* @param {string | typeof Hash} algorithm the algorithm name or a constructor creating a hash
* @returns {Hash} the hash
* @param algorithm the algorithm name or a constructor creating a hash
* @returns the hash
*/
export const createHash = (
algorithm:
Expand Down

0 comments on commit e1440e9

Please sign in to comment.