mirror of
https://github.com/nodejs/node.git
synced 2025-05-21 17:44:15 +00:00

Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
33 lines
715 B
JavaScript
33 lines
715 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
ObjectCreate,
|
|
} = primordials;
|
|
|
|
// Example:
|
|
// C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\nemailAddress=ry@clouds.org
|
|
function parseCertString(s) {
|
|
const out = ObjectCreate(null);
|
|
const parts = s.split('\n');
|
|
for (let i = 0, len = parts.length; i < len; i++) {
|
|
const sepIndex = parts[i].indexOf('=');
|
|
if (sepIndex > 0) {
|
|
const key = parts[i].slice(0, sepIndex);
|
|
const value = parts[i].slice(sepIndex + 1);
|
|
if (key in out) {
|
|
if (!Array.isArray(out[key])) {
|
|
out[key] = [out[key]];
|
|
}
|
|
out[key].push(value);
|
|
} else {
|
|
out[key] = value;
|
|
}
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
module.exports = {
|
|
parseCertString
|
|
};
|