mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-24 01:29:19 +02:00
some progress
This commit is contained in:
parent
aea93a5527
commit
e3c15bd288
1388 changed files with 306946 additions and 68323 deletions
48
node_modules/mpath/lib/stringToParts.js
generated
vendored
Normal file
48
node_modules/mpath/lib/stringToParts.js
generated
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = function stringToParts(str) {
|
||||
const result = [];
|
||||
|
||||
let curPropertyName = '';
|
||||
let state = 'DEFAULT';
|
||||
for (let i = 0; i < str.length; ++i) {
|
||||
// Fall back to treating as property name rather than bracket notation if
|
||||
// square brackets contains something other than a number.
|
||||
if (state === 'IN_SQUARE_BRACKETS' && !/\d/.test(str[i]) && str[i] !== ']') {
|
||||
state = 'DEFAULT';
|
||||
curPropertyName = result[result.length - 1] + '[' + curPropertyName;
|
||||
result.splice(result.length - 1, 1);
|
||||
}
|
||||
|
||||
if (str[i] === '[') {
|
||||
if (state !== 'IMMEDIATELY_AFTER_SQUARE_BRACKETS') {
|
||||
result.push(curPropertyName);
|
||||
curPropertyName = '';
|
||||
}
|
||||
state = 'IN_SQUARE_BRACKETS';
|
||||
} else if (str[i] === ']') {
|
||||
if (state === 'IN_SQUARE_BRACKETS') {
|
||||
state = 'IMMEDIATELY_AFTER_SQUARE_BRACKETS';
|
||||
result.push(curPropertyName);
|
||||
curPropertyName = '';
|
||||
} else {
|
||||
state = 'DEFAULT';
|
||||
curPropertyName += str[i];
|
||||
}
|
||||
} else if (str[i] === '.') {
|
||||
if (state !== 'IMMEDIATELY_AFTER_SQUARE_BRACKETS') {
|
||||
result.push(curPropertyName);
|
||||
curPropertyName = '';
|
||||
}
|
||||
state = 'DEFAULT';
|
||||
} else {
|
||||
curPropertyName += str[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (state !== 'IMMEDIATELY_AFTER_SQUARE_BRACKETS') {
|
||||
result.push(curPropertyName);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue