Skip to content

Commit

Permalink
Merge e5ad6c4 into 510ff65
Browse files Browse the repository at this point in the history
  • Loading branch information
elchininet committed Apr 27, 2021
2 parents 510ff65 + e5ad6c4 commit 554df65
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [2.1.2] - 2021-04-27

- Removed @emotion/hash dependency

## [2.1.1] - 2021-03-21

- Fix error using the library directly from the browser
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
"version": "git add .",
"postversion": "git push && git push --tags"
},
"dependencies": {
"@emotion/hash": "^0.8.0"
},
"devDependencies": {
"@types/jest": "^26.0.23",
"@types/node": "^15.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/classes/styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import hash from '@emotion/hash';
import { hash } from '@utilities/string';
import { Plane, View, Rotation, Rule, Fallbacks, RuleData } from '@types';
import { VIEW, SCALE, NAMESPACE } from '@constants';
import { kebab } from '@utilities/string';
Expand Down
67 changes: 66 additions & 1 deletion src/utilities/string.ts
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
export const kebab = (prop: string): string => prop.replace(/[A-Z]/g, '-$&').toLowerCase();
export const kebab = (prop: string): string => prop.replace(/[A-Z]/g, '-$&').toLowerCase();

// Taken from @emotion/hash package
// https://github.com/emotion-js/emotion/blob/f08dfda3fb62738836c1933e87e72abe7cf8e392/next-packages/hash/src/index.js
// Which is inspired in murmurhash (https://github.com/garycourt/murmurhash-js)
// Ported from https://github.com/aappleby/smhasher/blob/61a0530f28277f2e850bfc39600ce61d02b518de/src/MurmurHash2.cpp#L37-L86
export const hash = (str: string): string => {

// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.

// const m = 0x5bd1e995;
// const r = 24;

// Initialize the hash

let h = 0

// Mix 4 bytes at a time into the hash

let k;
let i = 0;
let len = str.length;

for (; len >= 4; ++i, len -= 4) {
k =
(str.charCodeAt(i) & 0xff) |
((str.charCodeAt(++i) & 0xff) << 8) |
((str.charCodeAt(++i) & 0xff) << 16) |
((str.charCodeAt(++i) & 0xff) << 24);

/* Math.imul(k, m): */
k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0xe995) << 16);

k ^= /* k >>> r: */ k >>> 24;

h =
/* Math.imul(k, m): */
((k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0xe995) << 16)) ^
/* Math.imul(h, m): */
((h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0xe995) << 16));
}

// Handle the last few bytes of the input array
switch (len) {
case 3:
h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
case 2:
h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
case 1:
h ^= str.charCodeAt(i) & 0xff;
/* Math.imul(h, m): */
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0xe995) << 16)
}

// Do a few final mixes of the hash to ensure the last few
// bytes are well-incorporated.

h ^= h >>> 13;

/* Math.imul(h, m): */
h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0xe995) << 16);

return ((h ^ (h >>> 15)) >>> 0).toString(36);

};
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,6 @@
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.2.tgz#8f03a22a04de437254e8ce8cc84ba39689288752"
integrity sha512-HyYEUDeIj5rRQU2Hk5HTB2uHsbRQpF70nvMhVzi+VJR0X+xNEhjPui4/kBf3VeH/wqD28PT4sVOm8qqLjBrSZg==

"@emotion/hash@^0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.8.0.tgz#bbbff68978fefdbe68ccb533bc8cbe1d1afb5413"
integrity sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow==

"@eslint/eslintrc@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.0.tgz#99cc0a0584d72f1df38b900fb062ba995f395547"
Expand Down

0 comments on commit 554df65

Please sign in to comment.