Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default (obj = {}) => {
let
defaultObj = defaults(obj, { width: 45, height: 45 }),
hashedId = MurmurHash3(obj["id"]).result();
return img(
Object.assign(
{
src: `https://robohash.org/${hashedId.toString(16)}.png?size=${at(obj, 'width', 'height').join('x')}`,
style: { backgroundColor: _.get(RAINBOW_COLORS, ~~(hashedId / MAX_HASH * RAINBOW_COLORS.length)) }
},
omit(defaultObj, 'src') // "..." object expander is a late es6 addition
)
);
};
export function hashFileSystemDataLists(data) {
if (!data.length) {
return '';
}
const hash = new Murmur(data[0][0]);
data.forEach((entry, i) => {
// On the first iteration, skip the first cell as we applied it above
if (i !== 0) {
hash.hash(entry[0]);
}
hash.hash(String(entry[1]));
});
return hash.result();
}
], (err, data) => {
if (err) return cb(err);
const [packageJson, dirs] = data;
const hash = murmur(packageJson);
async.map(
dirs,
(dir, cb) => {
const dirname = path.join(rootNodeModules, dir);
fs.stat(dirname, cb)
},
(err, stats) => {
if (err) return cb(err);
stats.forEach((stat, i) => {
const dir = dirs[i];
const mtime = stat.mtime.getTime();
hash.hash(dir + mtime);
});
getFileChunk(entry: string, label: ?string = null): ChunkFile {
let generatedLabel = label
if (!generatedLabel) {
generatedLabel = new Imurmurhash()
.hash(entry)
.result()
.toString()
}
return {
type: 'file',
format: path.extname(entry),
entry,
label: generatedLabel,
imports: [],
}
}
async report(report: Object): Promise {
getSimpleChunk(entry: ?string = null, imports: Array = [], label: ?string = null): ChunkSimple {
let generatedLabel = label
if (!generatedLabel) {
if (entry) {
generatedLabel = new Imurmurhash()
.hash(entry)
.result()
.toString()
} else {
throw new Error('Either entry or label are required to make a chunk')
}
}
return {
type: 'simple',
format: '.js',
entry,
label: generatedLabel,
imports,
}
}
.map(entry => new Murmur(entry.toString()).result())
.join('_');
.map(({ timestamp, event: { object: { spec } } })=>({
create: new Date(timestamp),
hash: MurmurHash3(JSON.stringify(spec)).result(),
spec
}))
.reduce((ac, cur)=> _.get(_.last(ac), 'hash') !== cur["hash"] ? ac.concat([cur]) : ac, [])
async registerHost(dependencies: Dependencies = {}): Promise {
let result: Maybe = undefined;
const sortedDependencies = Object.entries(dependencies).sort(([nameA], [nameB]) => nameA.localeCompare(nameB));
const id = MurmurHash3(JSON.stringify(sortedDependencies)).result();
const index = await this.storage.getIndex();
if (!index[id]) {
result = await this.upsertIndex({
id,
dependencies
});
}
return {
id,
issues: result ? result.issues : {},
index: result ? result.index : index[id].components
};
}
export function generateMurmurHash(key) {
if (!isArray(key)) {
return String(new Murmur(key.toString()).result());
}
if (!key.length) {
throw new Error('Key array does not contain any entries');
}
return key
.map(entry => new Murmur(entry.toString()).result())
.join('_');
}
export function murmurFilename(cacheKey) {
const hash = murmur(cacheKey).result();
return hash + '.json';
}