UNPKG

3.73 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../src/utils/NameGenerator.js"],"names":["escapeInvalidIdentifierCharacters","s","res","c","charCodeAt","base62characters","base62encode","n","f","length","NameGenerator","constructor","forbiddenNames","debugNames","uniqueSuffix","prefix","uidCounter","generate","debugSuffix","id","has"],"mappings":";;;;;;;AAWA;;;;AAXA;;;;;;;;AAaA,SAASA,iCAAT,CAA2CC,CAA3C,EAA8D;AAC5D,MAAIC,GAAG,GAAG,EAAV;;AACA,OAAK,IAAIC,CAAT,IAAcF,CAAd,EACE,IAAKE,CAAC,IAAI,GAAL,IAAYA,CAAC,IAAI,GAAlB,IAA2BA,CAAC,IAAI,GAAL,IAAYA,CAAC,IAAI,GAA5C,IAAqDA,CAAC,IAAI,GAAL,IAAYA,CAAC,IAAI,GAA1E,EAAgFD,GAAG,IAAIC,CAAP,CAAhF,KACKD,GAAG,IAAI,MAAMC,CAAC,CAACC,UAAF,CAAa,CAAb,CAAb;;AACP,SAAOF,GAAP;AACD;;AAED,MAAMG,gBAAgB,GAAG,gEAAzB;;AACA,SAASC,YAAT,CAAsBC,CAAtB,EAAyC;AACvC,0BAAU,CAACA,CAAC,GAAG,CAAL,MAAYA,CAAZ,IAAiBA,CAAC,IAAI,CAAhC;AACA,MAAIA,CAAC,KAAK,CAAV,EAAa,OAAO,GAAP;AACb,MAAIN,CAAC,GAAG,EAAR;;AACA,SAAOM,CAAC,GAAG,CAAX,EAAc;AACZ,QAAIC,CAAC,GAAGD,CAAC,GAAGF,gBAAgB,CAACI,MAA7B;AACAR,IAAAA,CAAC,GAAGI,gBAAgB,CAACG,CAAD,CAAhB,GAAsBP,CAA1B;AACAM,IAAAA,CAAC,GAAG,CAACA,CAAC,GAAGC,CAAL,IAAUH,gBAAgB,CAACI,MAA/B;AACD;;AACD,SAAOR,CAAP;AACD;;AAEM,MAAMS,aAAN,CAAoB;AACzBC,EAAAA,WAAW,CAACC,cAAD,EAA8BC,UAA9B,EAAmDC,YAAnD,EAAyEC,MAAzE,EAAyF;AAClG,SAAKA,MAAL,GAAcA,MAAd;AACA,SAAKC,UAAL,GAAkB,CAAlB;AACA,SAAKH,UAAL,GAAkBA,UAAlB;AACA,SAAKD,cAAL,GAAsBA,cAAtB;AACA,SAAKE,YAAL,GAAoBA,YAApB;AACD;;AAMDG,EAAAA,QAAQ,CAACC,WAAD,EAA+B;AACrC,QAAIC,EAAJ;;AACA,OAAG;AACDA,MAAAA,EAAE,GAAG,KAAKJ,MAAL,GAAcT,YAAY,CAAC,KAAKU,UAAL,EAAD,CAA/B;AACA,UAAI,KAAKF,YAAL,CAAkBL,MAAlB,GAA2B,CAA/B,EAAkCU,EAAE,IAAI,KAAKL,YAAX;;AAClC,UAAI,KAAKD,UAAT,EAAqB;AACnB,YAAIK,WAAJ,EAAiBC,EAAE,IAAI,MAAMnB,iCAAiC,CAACkB,WAAD,CAA7C,CAAjB,KACKC,EAAE,IAAI,GAAN;AACN;AACF,KAPD,QAOS,KAAKP,cAAL,CAAoBQ,GAApB,CAAwBD,EAAxB,CAPT;;AAQA,WAAOA,EAAP;AACD;;AAxBwB","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\n\nimport invariant from \"../invariant.js\";\n\nfunction escapeInvalidIdentifierCharacters(s: string): string {\n let res = \"\";\n for (let c of s)\n if ((c >= \"0\" && c <= \"9\") || (c >= \"a\" && c <= \"z\") || (c >= \"A\" && c <= \"Z\")) res += c;\n else res += \"_\" + c.charCodeAt(0);\n return res;\n}\n\nconst base62characters = \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\";\nfunction base62encode(n: number): string {\n invariant((n | 0) === n && n >= 0);\n if (n === 0) return \"0\";\n let s = \"\";\n while (n > 0) {\n let f = n % base62characters.length;\n s = base62characters[f] + s;\n n = (n - f) / base62characters.length;\n }\n return s;\n}\n\nexport class NameGenerator {\n constructor(forbiddenNames: Set<string>, debugNames: boolean, uniqueSuffix: string, prefix: string) {\n this.prefix = prefix;\n this.uidCounter = 0;\n this.debugNames = debugNames;\n this.forbiddenNames = forbiddenNames;\n this.uniqueSuffix = uniqueSuffix;\n }\n prefix: string;\n uidCounter: number;\n debugNames: boolean;\n forbiddenNames: Set<string>;\n uniqueSuffix: string;\n generate(debugSuffix: ?string): string {\n let id;\n do {\n id = this.prefix + base62encode(this.uidCounter++);\n if (this.uniqueSuffix.length > 0) id += this.uniqueSuffix;\n if (this.debugNames) {\n if (debugSuffix) id += \"_\" + escapeInvalidIdentifierCharacters(debugSuffix);\n else id += \"_\";\n }\n } while (this.forbiddenNames.has(id));\n return id;\n }\n}\n"],"file":"NameGenerator.js"}
\No newline at end of file