Safe identity placeholder
yarn add id-placeholder
import Placeholder from 'id-placeholder'
new Placeholder().get(0xdeedbeef)
// ppllaacceehhoollddeerraargkoahaaaaaaaaamcunedjrreeddlloohheeccaallpp
// ^^^^^^^^^^^^^^^^^^^^^^
// |> `prefix`: duplicated `"placeholder"`
// ppllaacceehhoollddeerraargkoahaaaaaaaaamcunedjrreeddlloohheeccaallpp
// ^^^^^^^^
// |> `identity`: random 8 string
// ppllaacceehhoollddeerraargkoahaaaaaaaaamcunedjrreeddlloohheeccaallpp
// ^^^^^^^^^^^^^^^^
// |> `index`: encoded index `0xdeedbeef`, fixed length 16
// ppllaacceehhoollddeerraargkoahaaaaaaaaamcunedjrreeddlloohheeccaallpp
// ^^^^^^^^^^^^^^^^^^^^^^
// |> `suffix`: reversed string of `prefix`
get placeholder by index
new Placeholder().get(0xdeedbeef)
get auto increased placeholder
const placeholder = new Placeholder()
placeholder.generate()
// ->
// {
// index: 0,
// ...,
// }
placeholder.generate()
// ->
// {
// index: 1,
// ...,
// }
reset counter
const placeholder = new Placeholder()
placeholder.generate().index
// -> 0
placeholder.generate().index
// -> 1
placeholder.reset()
// reset to counter
placeholder.generate().index
// -> 0
split string into pieces
const placeholder = new Placeholder()
const string = `foo${placeholder.get(0xdeedbeef)}bar`
// -> foo...bar
placeholder.split(string)
// -> [StringPiece, PlaceholderPiece, StringPiece]
{
isPlaceholder: false,
string: 'foo',
}
{
isPlaceholder: true,
index: 3740122863, // 0xdeedbeef
encodedIndex: 'aaaaaaaaamcunedj', // encoded version 0xdeedbeef
placeholder, // placeholder string
prefix,
identity,
suffix,
}
check is string a placeholder
check is string has a placeholder
check is string starts with a placeholder
check is string end with a placeholder
shortcut for options.namespace
new Placeholder('foobar')
// equals to
new Placeholder({namespace: 'foobar'})
- type:
string
- default:
"placeholder"
- type:
string
- default: duplicate string of namespace
new Placeholder({namespace: 'foo'}).prefix
// -> 'ffoooo'
- type:
string
- default: reversed string of prefix
new Placeholder({prefix: 'foo'}).suffix
// -> 'oof'
new Placeholder({namespace: 'foo'}).suffix
// -> 'ooooff'
- type:
string
- default: random string of 8 length