MCPcopy Create free account
hub / github.com/cryptii/cryptii / performEncode

Method performEncode

src/Encoder/CaseTransform.js:57–88  ·  view source on GitHub ↗

* Performs encode on given content. * @protected * @param {Chain} content * @return {number[]|string|Uint8Array|Chain} Encoded content

(content)

Source from the content-addressed store, hash-verified

55 * @return {number[]|string|Uint8Array|Chain} Encoded content
56 */
57 performEncode (content) {
58 switch (this.getSettingValue('case')) {
59 case 'lower':
60 return content.toLowerCase()
61
62 case 'upper':
63 return content.toUpperCase()
64
65 case 'capitalize':
66 return Chain.wrap(
67 content.getString()
68 .replace(/\w\S*/ug, word =>
69 word.charAt(0).toUpperCase() + word.substr(1).toLowerCase())
70 )
71
72 case 'alternating':
73 return Chain.wrap(
74 content.getChars()
75 .map((char, index) =>
76 index % 2 === 0
77 ? char.toLowerCase()
78 : char.toUpperCase())
79 .join('')
80 )
81
82 case 'inverse':
83 return this._inverseCase(content)
84
85 default:
86 return content
87 }
88 }
89
90 /**
91 * Performs decode on given content.

Callers

nothing calls this directly

Calls 9

_inverseCaseMethod · 0.95
getSettingValueMethod · 0.80
toLowerCaseMethod · 0.80
toUpperCaseMethod · 0.80
wrapMethod · 0.80
getStringMethod · 0.80
substrMethod · 0.80
joinMethod · 0.80
getCharsMethod · 0.80

Tested by

no test coverage detected