File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import hash from '../hash.mjs' ;
2+
3+ describe ( 'hash()' , ( ) => {
4+ it ( 'returns the expected value' , ( ) => {
5+ expect ( hash ( 'foo' ) ) . toBe ( 'rL0Y20zC-F' ) ;
6+ } ) ;
7+
8+ it ( 'returns a 10-character string' , ( ) => {
9+ expect ( hash ( 'foo' ) ) . toHaveLength ( 10 ) ;
10+ expect ( hash ( '' ) ) . toHaveLength ( 10 ) ;
11+ expect ( hash ( 'a very long string that exceeds normal length' ) ) . toHaveLength ( 10 ) ;
12+ } ) ;
13+
14+ it ( 'returns consistent results for the same input' , ( ) => {
15+ expect ( hash ( 'foo' ) ) . toBe ( hash ( 'foo' ) ) ;
16+ } ) ;
17+
18+ it ( 'returns different results for different inputs' , ( ) => {
19+ expect ( hash ( 'foo' ) ) . not . toBe ( hash ( 'bar' ) ) ;
20+ } ) ;
21+ } ) ;
Original file line number Diff line number Diff line change 1- import MurmurHash3 from 'imurmurhash ' ;
1+ import { createHash } from 'node:crypto ' ;
22
33/**
44 * hash the given string
55 * @param {string } str the string to hash
66 * @returns {string } the hash
77 */
88export default function hash ( str ) {
9- return MurmurHash3 ( str ) . result ( ) . toString ( 36 ) ;
9+ // Why md5?
10+ // - Fastest performance
11+ // - Sufficient collision resistance for file paths and configurations
12+ // - Not need cryptographic security
13+ return createHash ( 'md5' ) . update ( str ) . digest ( 'base64url' ) . slice ( 0 , 10 ) ;
1014}
Original file line number Diff line number Diff line change 146146 "html-tags" : " ^5.1.0" ,
147147 "ignore" : " ^7.0.5" ,
148148 "import-meta-resolve" : " ^4.2.0" ,
149- "imurmurhash" : " ^0.1.4" ,
150149 "is-plain-object" : " ^5.0.0" ,
151150 "mathml-tag-names" : " ^4.0.0" ,
152151 "meow" : " ^14.1.0" ,
173172 "@types/debug" : " ^4.1.12" ,
174173 "@types/global-modules" : " ^2.0.2" ,
175174 "@types/globjoin" : " ^0.1.2" ,
176- "@types/imurmurhash" : " ^0.1.4" ,
177175 "@types/micromatch" : " ^4.0.10" ,
178176 "@types/normalize-path" : " ^3.0.2" ,
179177 "@types/postcss-less" : " ^4.0.7" ,
You can’t perform that action at this time.
0 commit comments