mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 18:26:24 +00:00

PR-URL: https://github.com/nodejs/node/pull/28853 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
23 lines
459 B
JavaScript
23 lines
459 B
JavaScript
'use strict';
|
|
|
|
module.exports = (string, separator) => {
|
|
if (!(typeof string === 'string' && typeof separator === 'string')) {
|
|
throw new TypeError('Expected the arguments to be of type `string`');
|
|
}
|
|
|
|
if (separator === '') {
|
|
return [string];
|
|
}
|
|
|
|
const separatorIndex = string.indexOf(separator);
|
|
|
|
if (separatorIndex === -1) {
|
|
return [string];
|
|
}
|
|
|
|
return [
|
|
string.slice(0, separatorIndex),
|
|
string.slice(separatorIndex + separator.length)
|
|
];
|
|
};
|