WIP - add extractor, generate snippet_data
This commit is contained in:
30
node_modules/kebab-hash/lib/index.js
generated
vendored
Normal file
30
node_modules/kebab-hash/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _crypto = require("crypto");
|
||||
|
||||
var _lodash = require("lodash.kebabcase");
|
||||
|
||||
var _lodash2 = _interopRequireDefault(_lodash);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// Given a string `input` get the first `length` characters of the md5 hash of
|
||||
// the `input` string. This effectively creates a "short" hash for a given
|
||||
// input.
|
||||
var shortHash = function shortHash(input) {
|
||||
var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
|
||||
return (0, _crypto.createHash)("md5").update(input).digest("hex").substr(0, length);
|
||||
};
|
||||
|
||||
// Given `input` return the kebab case version with a short has appended.
|
||||
var kebabHash = function kebabHash(path) {
|
||||
var hashLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
|
||||
return (0, _lodash2.default)(path) + "-" + shortHash(path, hashLength);
|
||||
};
|
||||
|
||||
exports.default = kebabHash;
|
||||
module.exports = exports["default"];
|
||||
18
node_modules/kebab-hash/lib/index.js.flow
generated
vendored
Normal file
18
node_modules/kebab-hash/lib/index.js.flow
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
// @flow
|
||||
import { createHash } from "crypto";
|
||||
import kebabCase from "lodash.kebabcase";
|
||||
|
||||
// Given a string `input` get the first `length` characters of the md5 hash of
|
||||
// the `input` string. This effectively creates a "short" hash for a given
|
||||
// input.
|
||||
const shortHash = (input: string, length: number = 3): string =>
|
||||
createHash(`md5`)
|
||||
.update(input)
|
||||
.digest(`hex`)
|
||||
.substr(0, length);
|
||||
|
||||
// Given `input` return the kebab case version with a short has appended.
|
||||
const kebabHash = (path: string, hashLength: number = 3): string =>
|
||||
`${kebabCase(path)}-${shortHash(path, hashLength)}`;
|
||||
|
||||
export default kebabHash;
|
||||
27
node_modules/kebab-hash/lib/index.test.js
generated
vendored
Normal file
27
node_modules/kebab-hash/lib/index.test.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
var _index = require("./index");
|
||||
|
||||
var _index2 = _interopRequireDefault(_index);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
describe("Default hashLength", function () {
|
||||
test("Returns for /foo-bar", function () {
|
||||
expect((0, _index2.default)("/foo-bar")).toBe("foo-bar-096");
|
||||
});
|
||||
|
||||
test("Returns for /foo/bar", function () {
|
||||
expect((0, _index2.default)("/foo/bar")).toBe("foo-bar-1df");
|
||||
});
|
||||
});
|
||||
|
||||
describe("hashLength 5", function () {
|
||||
test("Returns for /foo-bar", function () {
|
||||
expect((0, _index2.default)("/foo-bar", 5)).toBe("foo-bar-09652");
|
||||
});
|
||||
|
||||
test("Returns for /foo/bar", function () {
|
||||
expect((0, _index2.default)("/foo/bar", 5)).toBe("foo-bar-1df48");
|
||||
});
|
||||
});
|
||||
21
node_modules/kebab-hash/lib/index.test.js.flow
generated
vendored
Normal file
21
node_modules/kebab-hash/lib/index.test.js.flow
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
import kebabHash from "./index";
|
||||
|
||||
describe("Default hashLength", () => {
|
||||
test("Returns for /foo-bar", () => {
|
||||
expect(kebabHash("/foo-bar")).toBe("foo-bar-096");
|
||||
});
|
||||
|
||||
test("Returns for /foo/bar", () => {
|
||||
expect(kebabHash("/foo/bar")).toBe("foo-bar-1df");
|
||||
});
|
||||
});
|
||||
|
||||
describe("hashLength 5", () => {
|
||||
test("Returns for /foo-bar", () => {
|
||||
expect(kebabHash("/foo-bar", 5)).toBe("foo-bar-09652");
|
||||
});
|
||||
|
||||
test("Returns for /foo/bar", () => {
|
||||
expect(kebabHash("/foo/bar", 5)).toBe("foo-bar-1df48");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user