-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from getlift/fix-cf-function-names
- Loading branch information
Showing
9 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import crypto from "crypto"; | ||
|
||
export function ensureNameMaxLength(name: string, maxLength: number): string { | ||
if (name.length <= maxLength) { | ||
return name; | ||
} | ||
|
||
const uniqueSuffix = crypto.createHash("md5").update(name).digest("hex").slice(0, 6); | ||
|
||
return name.slice(0, maxLength - uniqueSuffix.length - 1) + "-" + uniqueSuffix; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ensureNameMaxLength } from "../../../src/utils/naming"; | ||
|
||
describe("naming", () => { | ||
it("should not change names shorter than the limit", () => { | ||
expect(ensureNameMaxLength("foo", 3)).toEqual("foo"); | ||
}); | ||
|
||
it("should trim names with a unique suffix to stay under the limit", () => { | ||
expect(ensureNameMaxLength("foobarfoobarfoobarfoobar", 15)).toEqual("foobarfo-7ca709"); | ||
expect(ensureNameMaxLength("foobarfoobarfoobarfoobar", 15)).toHaveLength(15); | ||
// The suffix changes based on teh full string to avoid duplicates | ||
expect(ensureNameMaxLength("foobarfoofoofoofoofoofoo", 15)).not.toEqual("foobarfo-7ca709"); | ||
}); | ||
}); |